Easy way to add per command permissions/restrictions
Is there an easy way to add a restriction for any command so that it can only be ran by a member with a specific role or in a specific channel. i know you have to integrate it into your database but what the easiest way to set this up. ive been trying to set this up with a precondition for all commands where it checks the command name and checks the database to see if there are any restrictions in place
9 Replies
Database? No...
You can use preconditions with sapphire
Sapphire Framework
What are preconditions and how do they work? | Sapphire
Preconditions are classes that will determine whether or not a command should be ran according to certain conditions.
In the precondition, you can simply check if the member has a specific role, if they do, return this.ok() otherwise return this.error()
And I see you mentioned precondition also, if you're having trouble, show me your precondition code and/ or error
I wanted to make a command to allow members to setup their own restrictions per command
kinda like how dyno does
Oh right, I see. In this case, then yes a database would be the best approach.
In the simplest form, you can use
guildId-commandId
as the unique ID in the database, then have another 2 rows
1 for an array of role IDs and another for an array of channel IDs
I suppose you could do a row for user IDs tooAlright thanks
I managed to get the precondition part and the actual restriction part working. But i have one problem. I have some commands where i setup where i have permission levels setup like skyra but if a command has
PermissionLevels.Staff
the command wont run for a user who isnt a staff even if they are whitelisted. Is there a quick and easy way to make the restriction whitelist take priority over the PermissionLevel preconditions? I think i have to update every precondition for permission level to check for the whitelist.here is my current code:
https://srcshare.io/64cfc6aca596e819f6986cab
SrcShare
Easily share your source code with other developers.
I think you would have to update every precondition sadly.