Skip to content

Commit 2abbe55

Browse files
committed
Modify parameters and lookup
1 parent a13d57e commit 2abbe55

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

discord/bot.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Coroutine,
3838
List,
3939
Optional,
40+
Type,
4041
TypeVar,
4142
Union,
4243
)
@@ -131,24 +132,40 @@ def remove_application_command(
131132
"""
132133
return self.application_commands.pop(command.id)
133134

134-
def get_command(self, id: str, /) -> Optional[ApplicationCommand]:
135+
def get_command(
136+
self,
137+
name: str,
138+
guild_ids: Optional[List[int]] = None,
139+
type: Type[ApplicationCommand] = SlashCommand,
140+
) -> Optional[ApplicationCommand]:
135141
"""Get a :class:`.ApplicationCommand` from the internal list
136142
of commands.
137143
138144
.. versionadded:: 2.0
139145
140146
Parameters
141147
-----------
142-
id: :class:`str`
143-
The id of the command to get.
148+
name: :class:`str`
149+
The name of the command to get.
150+
guild_ids: List[:class:`int`]
151+
The guild ids associated to the command to get.
152+
type: Type[:class:`.ApplicationCommand`]
153+
The type of the command to get. Defaults to :class:`.SlashCommand`.
144154
145155
Returns
146156
--------
147-
Optional[:class:`ApplicationCommand`]
157+
Optional[:class:`.ApplicationCommand`]
148158
The command that was requested. If not found, returns ``None``.
149159
"""
150160

151-
return self.application_commands.get(id)
161+
for command in self.application_commands.values():
162+
if (
163+
command.name == name
164+
and isinstance(command, type)
165+
):
166+
if guild_ids is not None and command.guild_ids != guild_ids:
167+
return
168+
return command
152169

153170
get_application_command = get_command
154171

0 commit comments

Comments
 (0)