Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit b45829d

Browse files
committed
Really obscure bugfix
* Commands that have permissions that apply to all guilds tried to set those permissions in all the guilds that the bot is in, regardless of whether the command itself is in all those guilds. This is now fixed. * Minor improvements to debug logging.
1 parent b74a302 commit b45829d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

discord/ext/slash/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,8 +1443,8 @@ async def sync_cmds(self, state, todo, done, guild_id):
14431443
for k in {'name', 'description',
14441444
'options', 'default_permission'})
14451445
if up_to_date:
1446-
logger.debug('GET\t%s\tin guild\t%s', name, guild_id)
14471446
todo[name].id = int(done[name]['id'])
1447+
logger.debug('GET\t%s\t%s\tin guild\t%s', name, todo[name].id, guild_id)
14481448
else:
14491449
cmd_dict.pop('name') # can't pass this to PATCH
14501450
state['PATCH'].setdefault(guild_id, {})[name] \
@@ -1484,12 +1484,15 @@ async def register_permissions(self, guild_id: int = None):
14841484
async def _register_permissions(self, guild_id: int = None):
14851485
app_info = self.app_info
14861486
guild_path = f"/applications/{app_info.id}/guilds/{{0}}/commands/permissions"
1487-
guild_ids = {g.id for g in self.guilds} | {cmd.guild_id for cmd in self.slash}
1488-
guild_ids.discard(None)
1487+
all_guild_ids = {g.id for g in self.guilds} | {cmd.guild_id for cmd in self.slash}
1488+
all_guild_ids.discard(None)
14891489
guilds: Dict[int, List[dict]] = {}
14901490
for cmd in self.slash:
14911491
defaults = cmd.perms_dict(None)
14921492
if defaults['permissions']:
1493+
# don't set defaults in all guilds if the command itself
1494+
# is limited to only one guild
1495+
guild_ids = all_guild_ids if cmd.guild_id is None else {cmd.guild_id}
14931496
for gid in guild_ids:
14941497
# This is only for guilds that have no specific perms.
14951498
# Guilds that do have specific perms will have the default
@@ -1507,5 +1510,5 @@ async def _register_permissions(self, guild_id: int = None):
15071510
guilds.setdefault(gid, []).append(cmd.perms_dict(gid))
15081511
for guild_id, data in guilds.items():
15091512
route = _Route('PUT', guild_path.format(guild_id))
1513+
logger.debug('PUT\tpermissions for all commands\tin guild\t%s', guild_id)
15101514
await self.http.request(route, json=data)
1511-
logger.debug('PUT guild\t%s\tpermissions', guild_id)

0 commit comments

Comments
 (0)