Skip to content

Commit 0582332

Browse files
authored
Merge pull request #286 from JellyWX/master
debug_guild option for testing global commands
2 parents d9ad74a + bfbb670 commit 0582332

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

discord_slash/client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SlashCommand:
2929
:type client: Union[discord.Client, discord.ext.commands.Bot]
3030
:param sync_commands: Whether to sync commands automatically. Default `False`.
3131
:type sync_commands: bool
32+
:param debug_guild: Guild ID of guild to use for testing commands. Prevents setting global commands in favor of guild commands, which update instantly
33+
:type debug_guild: int
3234
:param delete_from_unused_guilds: If the bot should make a request to set no commands for guilds that haven't got any commands registered in :class:``SlashCommand``. Default `False`.
3335
:type delete_from_unused_guilds: bool
3436
:param sync_on_cog_reload: Whether to sync commands on cog reload. Default `False`.
@@ -55,6 +57,7 @@ def __init__(
5557
self,
5658
client: typing.Union[discord.Client, commands.Bot],
5759
sync_commands: bool = False,
60+
debug_guild: typing.Optional[int] = None,
5861
delete_from_unused_guilds: bool = False,
5962
sync_on_cog_reload: bool = False,
6063
override_type: bool = False,
@@ -67,6 +70,7 @@ def __init__(
6770
self.logger = logging.getLogger("discord_slash")
6871
self.req = http.SlashCommandRequest(self.logger, self._discord, application_id)
6972
self.sync_commands = sync_commands
73+
self.debug_guild = debug_guild
7074
self.sync_on_cog_reload = sync_on_cog_reload
7175

7276
if self.sync_commands:
@@ -373,7 +377,8 @@ async def sync_all_commands(
373377
permissions_map = {}
374378
cmds = await self.to_dict()
375379
self.logger.info("Syncing commands...")
376-
cmds_formatted = {None: cmds["global"]}
380+
# if debug_guild is set, global commands get re-routed to the guild to update quickly
381+
cmds_formatted = {self.debug_guild: cmds["global"]}
377382
for guild in cmds["guild"]:
378383
cmds_formatted[guild] = cmds["guild"][guild]
379384

0 commit comments

Comments
 (0)