#Check if a member has certain Permissions

1 messages · Page 1 of 1 (latest)

jaunty forge
#

I want to check if a member has required permissions or if the user calling the command has required permissions. I'm not exactly sure how to validate that?

tired pasture
#

[(Slash)RequirePermissions(Permissions)]

#

@red sandal RequirePermissions

red sandalBOT
patent rain
#

but if you want to reply a message like 'You can't use this command'

#

you have to check that user's permissions manually

#

Usage of the attribute SlashRequireUserPermissions:

[SlashCommand("test", "test command")] [SlashRequireUserPermissions(Permissions.Administrator)] public static async Task test2(InteractionContext ctx) { await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Command Executed Successfully")); }

#

if you use this attribute, the interaction will fail

#

Usage of the DiscordMember.Permissions:

` [SlashCommand("test", "test command")]
public static async Task test(InteractionContext ctx)
{
Permissions userPermissions = ctx.Member.Permissions;

        if(!userPermissions.HasPermission(Permissions.Administrator))
        {
            await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("You don't have the required permission"));
            return;
        }

        await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Command Executed Successfully"));
    }`