setExemptChannels method

Future<void> setExemptChannels(
  1. List<GuildChannel> channels, {
  2. String? reason,
})

Defines which roles will not be affected by this

Example :

final channel = guild.channels.cache.get('240561194958716924');

if (channel != null) {
  await rule.setExemptChannels([channel]);
}

Implementation

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

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

  if (response.statusCode == 200) {
    exemptChannels = channels;
  }
}