Skip to content

Commit 45b7cf5

Browse files
committed
Create application_commands property
1 parent 2abbe55 commit 45b7cf5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

discord/bot.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,23 @@ class ApplicationCommandMixin:
8181
def __init__(self, *args, **kwargs) -> None:
8282
super().__init__(*args, **kwargs)
8383
self._pending_application_commands = []
84-
self.application_commands = {}
84+
self._application_commands = {}
8585

8686
@property
8787
def pending_application_commands(self):
8888
return self._pending_application_commands
8989

9090
@property
9191
def commands(self) -> List[Union[ApplicationCommand, Any]]:
92-
commands = list(self.application_commands.values())
92+
commands = self.application_commands
9393
if self._supports_prefixed_commands:
9494
commands += self.prefixed_commands
9595
return commands
9696

97+
@property
98+
def application_commands(self) -> List[ApplicationCommand]:
99+
return list(self._application_commands.values())
100+
97101
def add_application_command(self, command: ApplicationCommand) -> None:
98102
"""Adds a :class:`.ApplicationCommand` into the internal list of commands.
99103
@@ -130,7 +134,7 @@ def remove_application_command(
130134
The command that was removed. If the name is not valid then
131135
``None`` is returned instead.
132136
"""
133-
return self.application_commands.pop(command.id)
137+
return self._application_commands.pop(command.id)
134138

135139
def get_command(
136140
self,
@@ -158,7 +162,7 @@ def get_command(
158162
The command that was requested. If not found, returns ``None``.
159163
"""
160164

161-
for command in self.application_commands.values():
165+
for command in self._application_commands.values():
162166
if (
163167
command.name == name
164168
and isinstance(command, type)
@@ -229,7 +233,7 @@ async def register_commands(self) -> None:
229233
guild_ids=None,
230234
type=i["type"],
231235
)
232-
self.application_commands[i["id"]] = cmd
236+
self._application_commands[i["id"]] = cmd
233237

234238
# Permissions (Roles will be converted to IDs just before Upsert for Global Commands)
235239
global_permissions.append({"id": i["id"], "permissions": cmd.permissions})
@@ -263,7 +267,7 @@ async def register_commands(self) -> None:
263267
else:
264268
for i in cmds:
265269
cmd = find(lambda cmd: cmd.name == i["name"] and cmd.type == i["type"] and int(i["guild_id"]) in cmd.guild_ids, self.pending_application_commands)
266-
self.application_commands[i["id"]] = cmd
270+
self._application_commands[i["id"]] = cmd
267271

268272
# Permissions
269273
permissions = [
@@ -354,7 +358,7 @@ async def register_commands(self) -> None:
354358
if len(new_cmd_perm["permissions"]) > 10:
355359
print(
356360
"Command '{name}' has more than 10 permission overrides in guild ({guild_id}).\nwill only use the first 10 permission overrides.".format(
357-
name=self.application_commands[new_cmd_perm["id"]].name,
361+
name=self._application_commands[new_cmd_perm["id"]].name,
358362
guild_id=guild_id,
359363
)
360364
)
@@ -404,7 +408,7 @@ async def process_application_commands(self, interaction: Interaction) -> None:
404408
return
405409

406410
try:
407-
command = self.application_commands[interaction.data["id"]]
411+
command = self._application_commands[interaction.data["id"]]
408412
except KeyError:
409413
self.dispatch("unknown_command", interaction)
410414
else:

0 commit comments

Comments
 (0)