Skip to content

Commit

Permalink
Improve and fix command registration (#957)
Browse files Browse the repository at this point in the history
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
  • Loading branch information
Luc1412 and Dorukyum authored Feb 7, 2022
1 parent 6fb972d commit 217a8fa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ async def register_commands(

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

for cmd in commands:
to_rep_with = [guild_id] if guild_id is not None else guild_id
cmd.guild_ids = to_rep_with
if guild_id is not None:
for cmd in commands:
to_rep_with = [guild_id]
cmd.guild_ids = to_rep_with

is_global = guild_id is None

Expand Down Expand Up @@ -537,7 +538,8 @@ async def sync_commands(
for cmd in commands:
cmd.guild_ids = guild_ids

registered_commands = await self.register_commands(commands, force=force)
global_commands = [cmd for cmd in commands if cmd.guild_ids is None]
registered_commands = await self.register_commands(global_commands, force=force)

cmd_guild_ids = []
registered_guild_commands = {}
Expand All @@ -549,10 +551,12 @@ async def sync_commands(
if unregister_guilds is not None:
cmd_guild_ids.extend(unregister_guilds)
for guild_id in set(cmd_guild_ids):
guild_commands = [cmd for cmd in commands if cmd.guild_ids is not None and guild_id in cmd.guild_ids]
registered_guild_commands[guild_id] = await self.register_commands(
commands,
guild_commands,
guild_id=guild_id,
force=force)
force=force
)

# TODO: 2.1: Remove this and favor permissions v2
# Global Command Permissions
Expand Down

0 comments on commit 217a8fa

Please sign in to comment.