diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index 0a130383..9399fc90 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -1,5 +1,6 @@ using Discord; using Discord.Commands; +using Discord.WebSocket; using Microsoft.EntityFrameworkCore; using NadekoBot.Attributes; using NadekoBot.Services; @@ -32,6 +33,9 @@ namespace NadekoBot.Modules.Administration Chat, All } + private static readonly OverwritePermissions denyOverwrite = new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny); + + private static readonly new Logger _log = LogManager.GetCurrentClassLogger(); static MuteCommands() { @@ -152,21 +156,26 @@ namespace NadekoBot.Modules.Administration muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName) ?? await guild.CreateRoleAsync(defaultMuteRoleName, GuildPermissions.None).ConfigureAwait(false); } + } - foreach (var toOverwrite in (await guild.GetTextChannelsAsync())) + foreach (var toOverwrite in (await guild.GetTextChannelsAsync())) + { + try { - try + if (!toOverwrite.PermissionOverwrites.Select(x => x.Permissions).Contains(denyOverwrite)) { - await toOverwrite.AddPermissionOverwriteAsync(muteRole, new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny)) + await toOverwrite.AddPermissionOverwriteAsync(muteRole, denyOverwrite) .ConfigureAwait(false); + + await Task.Delay(200).ConfigureAwait(false); } - catch - { - // ignored - } - await Task.Delay(200).ConfigureAwait(false); + } + catch + { + // ignored } } + return muteRole; }