Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked get_application_command behaviour #1678

Merged
merged 9 commits into from
Oct 17, 2022
26 changes: 21 additions & 5 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down