Skip to content

Commit

Permalink
Reworked get_application_command behaviour (#1678)
Browse files Browse the repository at this point in the history
* get_application_command rework

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated to run in same for loop

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
  • Loading branch information
4 people committed Oct 17, 2022
1 parent c062339 commit 80941fe
Showing 1 changed file with 21 additions and 5 deletions.
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

0 comments on commit 80941fe

Please sign in to comment.