Dynamic disable Slash Command based on role
Is that possible dynamic enable a slash command for a specify role in a specifically guild?
7 Replies
If you're talking about fully disable i.e. it not showing in the UI, no, the Discord API has no option for that. You can set permissions that are required, that it. And even then server owners can overwrite whatever you set.
You can use Sapphire preconditions however which are runtime checks.
Gotcha. I was think in something like what mee6 do like disable a whole module (a group of slash commands) in the backend or dynamic set it to be available only for a specific role.
So if you are not qualified by the guild + module enable on backend + role the slash command does not even shows for you
mee6 uses a modified version of dpy and you're looking for https://www.sapphirejs.dev/docs/Guide/additional-information/implenenting-a-discordpy-like-cog-system then
Sapphire Framework
Implementing a discord.py like Cog system | Sapphire
Developer who come from the Python ecosystem may be familiar with the "[Cog]" system that discord.py has implemented.
but you will also need your own preconditions
setting enabled to false will disable it for all users everywhere
it's quite a bit of work
but possible
I will search about it. Thanks!
I've actually made a plugin that is very similar to that for my own bot if you need ideas. Been running it in production with no issues so far.
https://github.com/KBot-discord/plugins/tree/main/packages/modules
GitHub
plugins/packages/modules at main · KBot-discord/plugins
Sapphire plugins for KBot. Contribute to KBot-discord/plugins development by creating an account on GitHub.
Only issue is that it does not work with ESM due to how imports are loaded. Looking into that atm.