pycord icon indicating copy to clipboard operation
pycord copied to clipboard

commands.check()s for command groups

Open arvitus opened this issue 2 years ago • 3 comments

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

arvitus avatar May 23 '22 14:05 arvitus

You can pass the checks to the checks kwarg when creating a group.

plun1331 avatar May 23 '22 14:05 plun1331

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()], )

arvitus avatar May 23 '22 14:05 arvitus

This is due to the Types of Data accepted in the "checks" Parameter of SlashCommandGroup. While SlashCommandGroups 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.

DaTurr3t avatar Jul 17 '22 21:07 DaTurr3t