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

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
8 Replies
Ben
Ben2y ago
You can pass in a Permissionresolvable to the requiredUserPermissions option on a command to make sure the user running it has that permission.
jolly jack
jolly jackOP2y ago
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
Ben
Ben2y ago
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.
jolly jack
jolly jackOP2y ago
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
Ben
Ben2y ago
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.
jolly jack
jolly jackOP2y ago
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
Favna
Favna2y ago
You'll have to write your own function. Feel free to make a PR to @sapphire/discord.js-utilities after the fact.
Want results from more Discord servers?
Add your server