pycord
pycord copied to clipboard
commands.check()s for command groups
Summary
make commands.check()s work with (slash) command groups
What is the feature request for?
discord.ext.commands
The Problem
The has_role()
, is_owner()
, guild_only()
, etc. checks can currently only be added to commands, not to command groups.
So if I were to have a command group with 20 commands and wanted this group to be a guild only group I'd have to add the guild_only()
check to every of the 20 commands instead of just adding it to the group.
The Ideal Solution
The checks (decorators) work on (slash) command groups.
Currently groups can only be created using either group = bot.create_group(args)
or group = SlashCommandGroup(args)
. So there is need for a third option that involves defining a function like the command creation to make the decorators work.
The Current Solution
There is currently no solution afaik.
Additional Context
No response
You can pass the checks to the checks
kwarg when creating a group.
as a list? Like this? Or how would I add multiple checks?
btw this doesn't work for me.
message_group = discord.SlashCommandGroup( "message", "Interactions the bot can perform on its own messages.", checks=[commands.is_owner()], )
This is due to the Types of Data accepted in the "checks" Parameter of SlashCommandGroup
. While SlashCommandGroup
s checks
takes in List[Callable[[:class:.ApplicationContext], :class:bool]]
, all ext.commands
Checks return decorator functions. You can extract and use the actual check function by using e,g. commands.is_owner().predicate
.