mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-06 10:02:01 +00:00
[commands] Add get_app_commands and walk_app_commands to Cog
This commit is contained in:
parent
c26473d0eb
commit
f5b0717661
@ -375,6 +375,17 @@ class Cog(metaclass=CogMeta):
|
|||||||
"""
|
"""
|
||||||
return [c for c in self.__cog_commands__ if c.parent is None]
|
return [c for c in self.__cog_commands__ if c.parent is None]
|
||||||
|
|
||||||
|
def get_app_commands(self) -> List[Union[app_commands.Command[Self, ..., Any], app_commands.Group]]:
|
||||||
|
r"""Returns the app commands that are defined inside this cog.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
List[Union[:class:`discord.app_commands.Command`, :class:`discord.app_commands.Group`]]
|
||||||
|
A :class:`list` of :class:`discord.app_commands.Command`\s and :class:`discord.app_commands.Group`\s that are
|
||||||
|
defined inside this cog, not including subcommands.
|
||||||
|
"""
|
||||||
|
return [c for c in self.__cog_app_commands__ if c.parent is None]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def qualified_name(self) -> str:
|
def qualified_name(self) -> str:
|
||||||
""":class:`str`: Returns the cog's specified name, not the class name."""
|
""":class:`str`: Returns the cog's specified name, not the class name."""
|
||||||
@ -405,6 +416,19 @@ class Cog(metaclass=CogMeta):
|
|||||||
if isinstance(command, GroupMixin):
|
if isinstance(command, GroupMixin):
|
||||||
yield from command.walk_commands()
|
yield from command.walk_commands()
|
||||||
|
|
||||||
|
def walk_app_commands(self) -> Generator[Union[app_commands.Command[Self, ..., Any], app_commands.Group], None, None]:
|
||||||
|
"""An iterator that recursively walks through this cog's app commands and subcommands.
|
||||||
|
|
||||||
|
Yields
|
||||||
|
------
|
||||||
|
Union[:class:`discord.app_commands.Command`, :class:`discord.app_commands.Group`]
|
||||||
|
An app command or group from the cog.
|
||||||
|
"""
|
||||||
|
for command in self.__cog_app_commands__:
|
||||||
|
yield command
|
||||||
|
if isinstance(command, app_commands.Group):
|
||||||
|
yield from command.walk_commands()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def app_command(self) -> Optional[app_commands.Group]:
|
def app_command(self) -> Optional[app_commands.Group]:
|
||||||
"""Optional[:class:`discord.app_commands.Group`]: Returns the associated group with this cog.
|
"""Optional[:class:`discord.app_commands.Group`]: Returns the associated group with this cog.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user