From 5892bbd8b44fc8cff6b5bd2e476249e0a3d313c5 Mon Sep 17 00:00:00 2001 From: NextChai <75498301+NextChai@users.noreply.github.com> Date: Sun, 10 Apr 2022 23:00:18 -0400 Subject: [PATCH] Allow getting all commands from CommandTree.get_commands Co-authored-by: Danny --- discord/app_commands/tree.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index 314ba5d9c..c13a9bd2a 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -499,7 +499,7 @@ class CommandTree(Generic[ClientT]): self, *, guild: Optional[Snowflake] = ..., - type: Literal[AppCommandType.chat_input] = ..., + type: Literal[AppCommandType.chat_input], ) -> List[Union[Command[Any, ..., Any], Group]]: ... @@ -512,12 +512,25 @@ class CommandTree(Generic[ClientT]): ) -> Union[List[Union[Command[Any, ..., Any], Group]], List[ContextMenu]]: ... + @overload + def get_commands( + self, + *, + guild: Optional[Snowflake] = ..., + type: Optional[AppCommandType] = ..., + ) -> List[Union[Command[Any, ..., Any], Group, ContextMenu]]: + ... + def get_commands( self, *, guild: Optional[Snowflake] = None, - type: AppCommandType = AppCommandType.chat_input, - ) -> Union[List[Union[Command[Any, ..., Any], Group]], List[ContextMenu]]: + type: Optional[AppCommandType] = None, + ) -> Union[ + List[ContextMenu], + List[Union[Command[Any, ..., Any], Group]], + List[Union[Command[Any, ..., Any], Group, ContextMenu]], + ]: """Gets all application commands from the tree. Parameters @@ -525,15 +538,17 @@ class CommandTree(Generic[ClientT]): guild: Optional[:class:`~discord.abc.Snowflake`] The guild to get the commands from, not including global commands. If not given or ``None`` then only global commands are returned. - type: :class:`~discord.AppCommandType` - The type of commands to get. Defaults to :attr:`~discord.AppCommandType.chat_input`, - i.e. slash commands. + type: Optional[:class:`~discord.AppCommandType`] + The type of commands to get. When not given or ``None``, then all + command types are returned. Returns --------- - Union[List[:class:`ContextMenu`], List[Union[:class:`Command`, :class:`Group`]] + List[Union[:class:`ContextMenu`, :class:`Command`, :class:`Group`]] The application commands from the tree. """ + if type is None: + return self._get_all_commands(guild=guild) if type is AppCommandType.chat_input: if guild is None: