remove method

Future<void> remove(
  1. Snowflake id, {
  2. String? reason,
})

Remove a Role from the GuildMember

Example :

final Role? role = guild.roles.cache.get('446556480850755604');
final GuildMember? member = guild.members.cache.get('240561194958716924');
if (member != null && role != null) {
  await member.roles.remove(role.id)
}

You can pass a reason for the audit logs.

Example :

await member.roles.remove('446556480850755604', reason: 'Hello, World!');

Implementation

Future<void> remove (Snowflake id, {String? reason}) async {
  Response response = await ioc.use<DiscordApiHttpService>().destroy(url: '/guilds/${manager.guild.id}/members/$memberId/roles/$id')
    .auditLog(reason)
    .build();

  if (response.statusCode == 204) {
    cache.remove(id);
    return;
  }

  final payload = jsonDecode(response.body);

  if(payload['code'] == DiscordErrorsCode.missingPermissions.value) {
    container.use<ConsoleService>().warn('Bot don\'t have permissions to add or remove roles !');
    return;
  }
}