setExemptRoles method

Future<void> setExemptRoles(
  1. List<Role> roles, {
  2. String? reason,
})

Defines which roles will not be affected by this

Example :

final role = guild.roles.cache.get('240561194958716924');

if (role != null) {
  await rule.setExemptRoles([role]);
}

Implementation

Future<void> setExemptRoles(List<Role> roles, { String? reason }) async {
  int maxItems = 50;
  if (roles.length > maxItems) {
    TooManyException("The list of roles cannot exceed $maxItems items (currently ${roles.length} given)");
  }

  Response response = await ioc.use<DiscordApiHttpService>().patch(url: "/guilds/$guildId/auto-moderation/rules/$id")
    .payload({ 'exempt_roles': roles.map((Role role) => role.id) })
    .auditLog(reason)
    .build();

  if (response.statusCode == 200) {
    exemptRoles = roles;
  }
}