fetch method

  1. @override
Future<Role> fetch(
  1. Snowflake id
)
override

Fetch the item with the given id from the API.

Implementers should ensure this method updates the cache.

Implementation

@override
Future<Role> fetch(Snowflake id) async {
  // There isn't an endpoint to fetch a single role. Re-fetch all the roles to ensure they are up to date,
  // and return the matching role.
  final roles = await list();

  return roles.firstWhere(
    (role) => role.id == id,
    orElse: () => throw RoleNotFoundException(guildId, id),
  );
}