Skip to content

Commit

Permalink
Fix: Not applying channel permission overwrites correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Nov 20, 2021
1 parent ac912a9 commit 7db6d15
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ public override async Task<Result> CheckRequirementAsync(IInteractionContext con
throw new NullReferenceException("Missing permission overwrites");
}

var everyoneRoleId = guild.Roles.FirstOrDefault(x => x.Name == "@everyone")?.Id;

// Removed the denied permissions from the role perms.
// Apply the `everyone` role permission overwrites for this channel. This needs to be done first to avoid issues with the other overwrites.
var everyoneOverwrite = channel.PermissionOverwrites.FirstOrDefault(x => x.TargetId == guild.Roles.FirstOrDefault(z => z.Name == "@everyone")?.Id);
if (everyoneOverwrite is not null)
{
rolePerms |= everyoneOverwrite.Allow;
rolePerms &= ~everyoneOverwrite.Deny;
}

// Apply permission overwrites for the bot for this channel.
foreach (var permissionOverwrite in channel.PermissionOverwrites)
{
if (permissionOverwrite.TargetId == discordTokens.ApplicationId ||
permissionOverwrite.TargetId == everyoneRoleId ||
botMemberResult.Entity.Roles.Contains(permissionOverwrite.TargetId))
if (permissionOverwrite.TargetId == discordTokens.ApplicationId || botMemberResult.Entity.Roles.Contains(permissionOverwrite.TargetId))
{
rolePerms |= permissionOverwrite.Allow;
rolePerms &= ~permissionOverwrite.Deny;
Expand Down

0 comments on commit 7db6d15

Please sign in to comment.