diff --git a/discord/bot.py b/discord/bot.py index 94cb4ec032..3bde440f70 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -179,7 +179,7 @@ def get_application_command( self, name: str, guild_ids: list[int] | None = None, - type: type[ApplicationCommand] = SlashCommand, + type: type[ApplicationCommand] = ApplicationCommand, ) -> ApplicationCommand | None: """Get a :class:`.ApplicationCommand` from the internal list of commands. @@ -189,23 +189,39 @@ def get_application_command( Parameters ---------- name: :class:`str` - The name of the command to get. + The qualified name of the command to get. guild_ids: List[:class:`int`] The guild ids associated to the command to get. type: Type[:class:`.ApplicationCommand`] - The type of the command to get. Defaults to :class:`.SlashCommand`. + The type of the command to get. Defaults to :class:`.ApplicationCommand`. Returns ------- Optional[:class:`.ApplicationCommand`] The command that was requested. If not found, returns ``None``. """ - - for command in self._application_commands.values(): + commands = self._application_commands.values() + for command in commands: if command.name == name and isinstance(command, type): if guild_ids is not None and command.guild_ids != guild_ids: return return command + elif (names := name.split())[0] == command.name and isinstance( + command, SlashCommandGroup + ): + while len(names) > 1: + command = get(commands, name=names.pop(0)) + if not isinstance(command, SlashCommandGroup) or ( + guild_ids is not None and command.guild_ids != guild_ids + ): + return + commands = command.subcommands + command = get(commands, name=names.pop()) + if not isinstance(command, type) or ( + guild_ids is not None and command.guild_ids != guild_ids + ): + return + return command async def get_desynced_commands( self,