Skip to content

Commit 80941fe

Browse files
NeloBlivionpre-commit-ci[bot]LulalabyBobDotCom
authored
Reworked get_application_command behaviour (#1678)
* 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 <[email protected]> Co-authored-by: BobDotCom <[email protected]>
1 parent c062339 commit 80941fe

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

discord/bot.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def get_application_command(
179179
self,
180180
name: str,
181181
guild_ids: list[int] | None = None,
182-
type: type[ApplicationCommand] = SlashCommand,
182+
type: type[ApplicationCommand] = ApplicationCommand,
183183
) -> ApplicationCommand | None:
184184
"""Get a :class:`.ApplicationCommand` from the internal list
185185
of commands.
@@ -189,23 +189,39 @@ def get_application_command(
189189
Parameters
190190
----------
191191
name: :class:`str`
192-
The name of the command to get.
192+
The qualified name of the command to get.
193193
guild_ids: List[:class:`int`]
194194
The guild ids associated to the command to get.
195195
type: Type[:class:`.ApplicationCommand`]
196-
The type of the command to get. Defaults to :class:`.SlashCommand`.
196+
The type of the command to get. Defaults to :class:`.ApplicationCommand`.
197197
198198
Returns
199199
-------
200200
Optional[:class:`.ApplicationCommand`]
201201
The command that was requested. If not found, returns ``None``.
202202
"""
203-
204-
for command in self._application_commands.values():
203+
commands = self._application_commands.values()
204+
for command in commands:
205205
if command.name == name and isinstance(command, type):
206206
if guild_ids is not None and command.guild_ids != guild_ids:
207207
return
208208
return command
209+
elif (names := name.split())[0] == command.name and isinstance(
210+
command, SlashCommandGroup
211+
):
212+
while len(names) > 1:
213+
command = get(commands, name=names.pop(0))
214+
if not isinstance(command, SlashCommandGroup) or (
215+
guild_ids is not None and command.guild_ids != guild_ids
216+
):
217+
return
218+
commands = command.subcommands
219+
command = get(commands, name=names.pop())
220+
if not isinstance(command, type) or (
221+
guild_ids is not None and command.guild_ids != guild_ids
222+
):
223+
return
224+
return command
209225

210226
async def get_desynced_commands(
211227
self,

0 commit comments

Comments
 (0)