Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and fix command registration #957

Merged
merged 4 commits into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
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