Is there any utility to check if a member has permission to run a command?

Ffiery1/15/2023
Hi! I have a bot that needs to check if a member has permission to run a command and then do something accordingly (eg remove a role) and I'd rather not write something to check if the member has permission to use a command if it already exists
Solution:
You'll have to write your own function. Feel free to make a PR to @sapphire/discord.js-utilities after the fact.
Jump to solution
BBen1/15/2023
You can pass in a Permissionresolvable to the requiredUserPermissions option on a command to make sure the user running it has that permission.
Ffiery1/15/2023
Not like that permission I want to know if the user is allowed to run a command based on the slash command's permissions the guild may have overridden them it's a little confusing
BBen1/15/2023
I'm not sure I follow then. If the guild overrode the perms and the user doesnt have the ability to run the slash command, your bot should never receive an interaction.
Ffiery1/15/2023
The command in question gives the user a role, I need to know if the user loses access to the command to then remove the role accordingly I think I need https://discord.js.org/#/docs/discord.js/main/class/ApplicationCommandPermissionsManager?scrollTo=has but instead of it checking a single permission id, it'd iterate through and calculate whether the user has the ability to run a command I basically need to check if a member can run a command outside of the command itself, instead in a listener
BBen1/15/2023
I'm not sure if there is an event sent to the client on that kind of update. Scanning through https://www.sapphirejs.dev/docs/Documentation/api-framework/#events doesn't show anything obvious but I might have missed something.
Ffiery1/15/2023
I know there isn't a event unfortunately I'd probably use it in a member update as the user's ability to use a command would change based on roles I just need a function to check if a user can run a command based on the guild overrides
Solution
FFavna1/27/2023
You'll have to write your own function. Feel free to make a PR to @sapphire/discord.js-utilities after the fact.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Send and Reply from the editable-commands plugin do the same wrong thing.So I tried out both of them and none seems to respond on the interaction. what I want: image 1 whatwhat is this regex supposed to mean?What is the Best approach to developing a bot and reloading the new changes into it?I heard that logging in too many times can lead to rate limits. is there a good solution for this isHow do I create subcommands with different text input fields?Something like the image. The Docs only show how to create basic subcommands. Also in the Readme of Best Approach on separating Commands from their "run" file to a separate FolderFor context, I am super new to discordjs and this framework so apologizes if this question sounds odmessage commands are not workingtrying to update to v4 and the bot is not recognizing commands. i have enabled `loadMessageCommandLiBaseMessageOptions#components does not take BuildersHey everyone, so I've just downloaded djs 14.7.0 and i'm migrating my bot. I used to have a few `.seFailed to overwrite global application commandsSince updating to BulkOverwrite, I'm getting the following error: ``` 2023-01-12 22:00:07 - DEBUG - fetch channel returns undefinedHello. I have this code, which worked before I believe: ```js let theChannel = await client.channelmessage listeners stopped working in sapphire v4 on my bothi, this is my listener code: ```js const { Events, Listener, container } = require('@sapphire/framDuplicate identifier 'Command'I'm trying to create a basic slash command, but when I import the `Command` class from @sapphire/fraContext menu commands not being registeredHi, on updating to v4 I experienced the following error: ``` ApplicationCommandRegistry[report] FailIs there a way to disable ApplicationCommandRegistries logs?They happen on start-up and I don't want them between all of my formatted logging. Is there a way I Context Menu Interactions Not ReceivedI'm using the basic context menu command register (attached) and my run function is `async contextMeChatInputCommandError Event not firingI'm having trouble with this code https://hst.sh/odutopaniv.typescript in that the event is not firiWhat does commandError emit?I'm struggling to find what `commandError` emits when fired by sapphire.Am I doing this wrong? I feel like I'm doing this wrong.Hey there, In my ping command I'm doing `void interaction.reply(await resolveKey(interaction, "pingButton handler not triggeringHeyah @Helpers I basically added a button handler from https://www.sapphirejs.dev/docs/Guide/applicaHow to make auto idhints?so i want to make automatic idhints adding like idHints: [this.id] but i think it doesn't work so hoIssue on upgrade to v4On loading like any file (listeners and commands) it spits out a TypeError: import_discord2.Permissi