#Check if a member has certain Permissions
1 messages · Page 1 of 1 (latest)
Defines that usage of this command is restricted to members with specified permissions. This check also verifies that the bot has the same permissions.
1- ExecuteCheckAsync(...)
1- Permissions
2- (i) TypeId
3- IgnoreDms
if you use [SlashRequireUserPermissions()] attribute, the interaction will fail
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"));
}`