@@ -243,7 +243,7 @@ async def get_desynced_commands(self, guild_id: Optional[int] = None) -> List[Di
243243 # We can suggest the user to upsert, edit, delete, or bulk upsert the commands
244244
245245 return_value = []
246- cmds = copy . deepcopy ( self .pending_application_commands )
246+ cmds = self .pending_application_commands . copy ( )
247247
248248 if guild_id is None :
249249 registered_commands = await self .http .get_global_commands (self .user .id )
@@ -282,7 +282,7 @@ async def get_desynced_commands(self, guild_id: Optional[int] = None) -> List[Di
282282 if type (to_check [check ]) == list :
283283 for opt in to_check [check ]:
284284
285- cmd_vals = [val .get (opt , MISSING ) for val in as_dict [check ]]
285+ cmd_vals = [val .get (opt , MISSING ) for val in as_dict [check ]] if check in as_dict else []
286286 for i , val in enumerate (cmd_vals ):
287287 # We need to do some falsy conversion here
288288 # The API considers False (autocomplete) and [] (choices) to be falsy values
@@ -379,11 +379,12 @@ async def register_commands(
379379 if commands is None :
380380 commands = self .pending_application_commands
381381
382- commands = copy .deepcopy ( commands )
382+ 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
@@ -572,13 +576,15 @@ async def sync_commands(
572576 # Permissions (Roles will be converted to IDs just before Upsert for Global Commands)
573577 global_permissions .append ({"id" : i ["id" ], "permissions" : cmd .permissions })
574578
575- for guild_id , guild_data in registered_guild_commands .items ():
576- commands = registered_guild_commands [guild_id ]
579+ for guild_id , commands in registered_guild_commands .items ():
577580 guild_permissions : List = []
578581
579582 for i in commands :
580- cmd = find (lambda cmd : cmd .name == i ["name" ] and cmd .type == i ["type" ] and int (i ["guild_id" ]) in
581- cmd .guild_ids , self .pending_application_commands )
583+ cmd = find (lambda cmd : cmd .name == i ["name" ] and cmd .type == i ["type" ] and cmd .guild_ids is not None
584+ and int (i ["guild_id" ]) in cmd .guild_ids , self .pending_application_commands )
585+ if not cmd :
586+ # command has not been added yet
587+ continue
582588 cmd .id = i ["id" ]
583589 self ._application_commands [cmd .id ] = cmd
584590
@@ -588,7 +594,8 @@ async def sync_commands(
588594 for perm in cmd .permissions
589595 if perm .guild_id is None
590596 or (
591- perm .guild_id == guild_id and perm .guild_id in cmd .guild_ids
597+ perm .guild_id == guild_id and cmd .guild_ids is not None and perm .guild_id in
598+ cmd .guild_ids
592599 )
593600 ]
594601 guild_permissions .append (
@@ -601,7 +608,8 @@ async def sync_commands(
601608 for perm in global_command ["permissions" ]
602609 if perm .guild_id is None
603610 or (
604- perm .guild_id == guild_id and perm .guild_id in cmd .guild_ids
611+ perm .guild_id == guild_id and cmd .guild_ids is not None and perm .guild_id in
612+ cmd .guild_ids
605613 )
606614 ]
607615 guild_permissions .append (
@@ -636,7 +644,7 @@ async def sync_commands(
636644 }
637645 )
638646 else :
639- print (
647+ raise RuntimeError (
640648 "No Role ID found in Guild ({guild_id}) for Role ({role})" .format (
641649 guild_id = guild_id , role = permission ["id" ]
642650 )
@@ -669,9 +677,8 @@ async def sync_commands(
669677
670678 # Make sure we don't have over 10 overwrites
671679 if len (new_cmd_perm ["permissions" ]) > 10 :
672- print (
673- "Command '{name}' has more than 10 permission overrides in guild ({guild_id}).\n will only use "
674- "the first 10 permission overrides." .format (
680+ raise RuntimeError (
681+ "Command '{name}' has more than 10 permission overrides in guild ({guild_id})." .format (
675682 name = self ._application_commands [new_cmd_perm ["id" ]].name ,
676683 guild_id = guild_id ,
677684 )
@@ -687,7 +694,7 @@ async def sync_commands(
687694 self .user .id , guild_id , guild_cmd_perms
688695 )
689696 except Forbidden :
690- print (
697+ raise RuntimeError (
691698 f"Failed to add command permissions to guild { guild_id } " ,
692699 file = sys .stderr ,
693700 )
@@ -722,8 +729,8 @@ async def process_application_commands(self, interaction: Interaction, auto_sync
722729 if auto_sync is None :
723730 auto_sync = self .auto_sync_commands
724731 if interaction .type not in (
725- InteractionType .application_command ,
726- InteractionType .auto_complete
732+ InteractionType .application_command ,
733+ InteractionType .auto_complete ,
727734 ):
728735 return
729736
@@ -1399,15 +1406,15 @@ class Bot(BotBase, Client):
13991406
14001407 .. versionadded:: 1.3
14011408 debug_guilds: Optional[List[:class:`int`]]
1402- Guild IDs of guilds to use for testing commands. This is similar to debug_guild.
1403- The bot will not create any global commands if a debug_guilds is passed.
1409+ Guild IDs of guilds to use for testing commands.
1410+ The bot will not create any global commands if debug guild IDs are passed.
14041411
1405- ..versionadded:: 2.0
1412+ .. versionadded:: 2.0
14061413 auto_sync_commands: :class:`bool`
14071414 Whether or not to automatically sync slash commands. This will call sync_commands in on_connect, and in
14081415 :attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
14091416
1410- ..versionadded:: 2.0
1417+ .. versionadded:: 2.0
14111418 """
14121419
14131420 pass
0 commit comments