Skip to content

Commit 217a8fa

Browse files
Luc1412Dorukyum
andauthored
Improve and fix command registration (#957)
Co-authored-by: Dorukyum <[email protected]>
1 parent 6fb972d commit 217a8fa

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

discord/bot.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ async def register_commands(
381381

382382
commands = [copy.copy(cmd) for cmd in commands]
383383

384-
for cmd in commands:
385-
to_rep_with = [guild_id] if guild_id is not None else guild_id
386-
cmd.guild_ids = to_rep_with
384+
if guild_id is not None:
385+
for cmd in commands:
386+
to_rep_with = [guild_id]
387+
cmd.guild_ids = to_rep_with
387388

388389
is_global = guild_id is None
389390

@@ -537,7 +538,8 @@ async def sync_commands(
537538
for cmd in commands:
538539
cmd.guild_ids = guild_ids
539540

540-
registered_commands = await self.register_commands(commands, force=force)
541+
global_commands = [cmd for cmd in commands if cmd.guild_ids is None]
542+
registered_commands = await self.register_commands(global_commands, force=force)
541543

542544
cmd_guild_ids = []
543545
registered_guild_commands = {}
@@ -549,10 +551,12 @@ async def sync_commands(
549551
if unregister_guilds is not None:
550552
cmd_guild_ids.extend(unregister_guilds)
551553
for guild_id in set(cmd_guild_ids):
554+
guild_commands = [cmd for cmd in commands if cmd.guild_ids is not None and guild_id in cmd.guild_ids]
552555
registered_guild_commands[guild_id] = await self.register_commands(
553-
commands,
556+
guild_commands,
554557
guild_id=guild_id,
555-
force=force)
558+
force=force
559+
)
556560

557561
# TODO: 2.1: Remove this and favor permissions v2
558562
# Global Command Permissions

0 commit comments

Comments
 (0)