[commands] Add support for NSFW commands for hybrid commands

This commit is contained in:
Rapptz
2022-05-22 19:31:28 -04:00
parent 573b2121b7
commit 06c43d6772
3 changed files with 51 additions and 4 deletions

View File

@ -119,6 +119,11 @@ class CogMeta(type):
The group description of a cog. This is only applicable for :class:`GroupCog` instances.
By default, it's the same value as :attr:`description`.
.. versionadded:: 2.0
group_nsfw: :class:`bool`
Whether the application command group is NSFW. This is only applicable for :class:`GroupCog` instances.
By default, it's ``False``.
.. versionadded:: 2.0
"""
@ -126,6 +131,7 @@ class CogMeta(type):
__cog_description__: str
__cog_group_name__: str
__cog_group_description__: str
__cog_group_nsfw__: bool
__cog_settings__: Dict[str, Any]
__cog_commands__: List[Command[Any, ..., Any]]
__cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]]
@ -154,6 +160,7 @@ class CogMeta(type):
attrs['__cog_settings__'] = kwargs.pop('command_attrs', {})
attrs['__cog_name__'] = cog_name
attrs['__cog_group_name__'] = group_name
attrs['__cog_group_nsfw__'] = kwargs.pop('group_nsfw', False)
description = kwargs.pop('description', None)
if description is None:
@ -268,6 +275,7 @@ class Cog(metaclass=CogMeta):
group = app_commands.Group(
name=cls.__cog_group_name__,
description=cls.__cog_group_description__,
nsfw=cls.__cog_group_nsfw__,
parent=None,
guild_ids=getattr(cls, '__discord_app_commands_default_guilds__', None),
guild_only=getattr(cls, '__discord_app_commands_guild_only__', False),