Skip to content

Commit c58b5d9

Browse files
committed
change to_register to pending_application_commands
1 parent c326096 commit c58b5d9

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

discord/bot.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ class ApplicationCommandMixin:
5757
-----------
5858
app_commands: :class:`dict`
5959
A mapping of command id string to :class:`.ApplicationCommand` objects.
60-
to_register: :class:`list`
61-
A list of commands that have been added but not yet registered.
60+
pending_application_commands: :class:`list`
61+
A list of commands that have been added but not yet registered. This is read-only and is modified via other
62+
methods.
6263
"""
6364

6465
def __init__(self, *args, **kwargs) -> None:
6566
super().__init__(*args, **kwargs)
66-
self.to_register = []
67+
self._pending_application_commands = []
6768
self.app_commands = {}
6869

70+
@property
71+
def pending_application_commands(self):
72+
return self._pending_application_commands
73+
6974
def add_application_command(self, command: ApplicationCommand) -> None:
7075
"""Adds a :class:`.ApplicationCommand` into the internal list of commands.
7176
@@ -79,10 +84,10 @@ def add_application_command(self, command: ApplicationCommand) -> None:
7984
command: :class:`.ApplicationCommand`
8085
The command to add.
8186
"""
82-
87+
8388
if self.debug_guilds and command.guild_ids is None:
8489
command.guild_ids = self.debug_guilds
85-
self.to_register.append(command)
90+
self._pending_application_commands.append(command)
8691

8792
def remove_application_command(self, command: ApplicationCommand) -> Optional[ApplicationCommand]:
8893
"""Remove a :class:`.ApplicationCommand` from the internal list
@@ -227,7 +232,7 @@ async def handle_interaction(self, interaction: Interaction) -> None:
227232
else:
228233
self.dispatch('application_command_completion', ctx)
229234

230-
def slash_command(self, **kwargs):
235+
def slash_command(self, **kwargs) -> SlashCommand:
231236
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
232237
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
233238
This shortcut is made specifically for :class:`.SlashCommand`.
@@ -242,7 +247,7 @@ def slash_command(self, **kwargs):
242247
"""
243248
return self.application_command(cls=SlashCommand, **kwargs)
244249

245-
def user_command(self, **kwargs):
250+
def user_command(self, **kwargs) -> UserCommand:
246251
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
247252
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
248253
This shortcut is made specifically for :class:`.UserCommand`.
@@ -257,7 +262,7 @@ def user_command(self, **kwargs):
257262
"""
258263
return self.application_command(cls=UserCommand, **kwargs)
259264

260-
def message_command(self, **kwargs):
265+
def message_command(self, **kwargs) -> MessageCommand:
261266
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
262267
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
263268
This shortcut is made specifically for :class:`.MessageCommand`.
@@ -352,7 +357,7 @@ class BotBase(ApplicationCommandMixin, CogMixin):
352357
def __init__(self, *args, **kwargs):
353358
# super(Client, self).__init__(*args, **kwargs)
354359
# I replaced ^ with v and it worked
355-
super().__init__(*args, **kwargs)
360+
super().__init__(*args, **kwargs)
356361
self.debug_guild = kwargs.pop("debug_guild", None)
357362
self.debug_guilds = kwargs.pop("debug_guilds", None)
358363

@@ -361,7 +366,7 @@ def __init__(self, *args, **kwargs):
361366
self.debug_guilds = [self.debug_guild]
362367
else:
363368
raise TypeError('Both debug_guild and debug_guilds are set.')
364-
369+
365370
self._checks = []
366371
self._check_once = []
367372
self._before_invoke = None
@@ -373,7 +378,6 @@ async def on_connect(self):
373378
async def on_interaction(self, interaction):
374379
await self.handle_interaction(interaction)
375380

376-
377381
async def on_application_command_error(self, context: InteractionContext, exception: DiscordException) -> None:
378382
"""|coro|
379383
@@ -566,12 +570,12 @@ class Bot(BotBase, Client):
566570
Attributes
567571
-----------
568572
debug_guild: Optional[:class:`int`]
569-
Guild ID of a guild to use for testing commands. Prevents setting global commands
573+
Guild ID of a guild to use for testing commands. Prevents setting global commands
570574
in favor of guild commands, which update instantly.
571575
.. note::
572576
The bot will not create any global commands if a debug_guild is passed.
573577
debug_guilds: Optional[List[:class:`int`]]
574-
Guild IDs of guilds to use for testing commands. This is similar to debug_guild.
578+
Guild IDs of guilds to use for testing commands. This is similar to debug_guild.
575579
.. note::
576580
You cannot set both debug_guild and debug_guilds.
577581
"""
@@ -586,4 +590,4 @@ class AutoShardedBot(BotBase, AutoShardedClient):
586590
.. versionadded:: 2.0
587591
"""
588592

589-
pass
593+
pass

0 commit comments

Comments
 (0)