@@ -243,7 +243,7 @@ async def get_desynced_commands(self, guild_id: Optional[int] = None) -> List[Di
243
243
# We can suggest the user to upsert, edit, delete, or bulk upsert the commands
244
244
245
245
return_value = []
246
- cmds = copy . deepcopy ( self .pending_application_commands )
246
+ cmds = self .pending_application_commands . copy ( )
247
247
248
248
if guild_id is None :
249
249
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
282
282
if type (to_check [check ]) == list :
283
283
for opt in to_check [check ]:
284
284
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 []
286
286
for i , val in enumerate (cmd_vals ):
287
287
# We need to do some falsy conversion here
288
288
# The API considers False (autocomplete) and [] (choices) to be falsy values
@@ -379,11 +379,12 @@ async def register_commands(
379
379
if commands is None :
380
380
commands = self .pending_application_commands
381
381
382
- commands = copy .deepcopy ( commands )
382
+ commands = [ copy .copy ( cmd ) for cmd in commands ]
383
383
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
387
388
388
389
is_global = guild_id is None
389
390
@@ -537,7 +538,8 @@ async def sync_commands(
537
538
for cmd in commands :
538
539
cmd .guild_ids = guild_ids
539
540
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 )
541
543
542
544
cmd_guild_ids = []
543
545
registered_guild_commands = {}
@@ -549,10 +551,12 @@ async def sync_commands(
549
551
if unregister_guilds is not None :
550
552
cmd_guild_ids .extend (unregister_guilds )
551
553
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 ]
552
555
registered_guild_commands [guild_id ] = await self .register_commands (
553
- commands ,
556
+ guild_commands ,
554
557
guild_id = guild_id ,
555
- force = force )
558
+ force = force
559
+ )
556
560
557
561
# TODO: 2.1: Remove this and favor permissions v2
558
562
# Global Command Permissions
@@ -572,13 +576,15 @@ async def sync_commands(
572
576
# Permissions (Roles will be converted to IDs just before Upsert for Global Commands)
573
577
global_permissions .append ({"id" : i ["id" ], "permissions" : cmd .permissions })
574
578
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 ():
577
580
guild_permissions : List = []
578
581
579
582
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
582
588
cmd .id = i ["id" ]
583
589
self ._application_commands [cmd .id ] = cmd
584
590
@@ -588,7 +594,8 @@ async def sync_commands(
588
594
for perm in cmd .permissions
589
595
if perm .guild_id is None
590
596
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
592
599
)
593
600
]
594
601
guild_permissions .append (
@@ -601,7 +608,8 @@ async def sync_commands(
601
608
for perm in global_command ["permissions" ]
602
609
if perm .guild_id is None
603
610
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
605
613
)
606
614
]
607
615
guild_permissions .append (
@@ -636,7 +644,7 @@ async def sync_commands(
636
644
}
637
645
)
638
646
else :
639
- print (
647
+ raise RuntimeError (
640
648
"No Role ID found in Guild ({guild_id}) for Role ({role})" .format (
641
649
guild_id = guild_id , role = permission ["id" ]
642
650
)
@@ -669,9 +677,8 @@ async def sync_commands(
669
677
670
678
# Make sure we don't have over 10 overwrites
671
679
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 (
675
682
name = self ._application_commands [new_cmd_perm ["id" ]].name ,
676
683
guild_id = guild_id ,
677
684
)
@@ -687,7 +694,7 @@ async def sync_commands(
687
694
self .user .id , guild_id , guild_cmd_perms
688
695
)
689
696
except Forbidden :
690
- print (
697
+ raise RuntimeError (
691
698
f"Failed to add command permissions to guild { guild_id } " ,
692
699
file = sys .stderr ,
693
700
)
@@ -722,8 +729,8 @@ async def process_application_commands(self, interaction: Interaction, auto_sync
722
729
if auto_sync is None :
723
730
auto_sync = self .auto_sync_commands
724
731
if interaction .type not in (
725
- InteractionType .application_command ,
726
- InteractionType .auto_complete
732
+ InteractionType .application_command ,
733
+ InteractionType .auto_complete ,
727
734
):
728
735
return
729
736
@@ -1399,15 +1406,15 @@ class Bot(BotBase, Client):
1399
1406
1400
1407
.. versionadded:: 1.3
1401
1408
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.
1404
1411
1405
- ..versionadded:: 2.0
1412
+ .. versionadded:: 2.0
1406
1413
auto_sync_commands: :class:`bool`
1407
1414
Whether or not to automatically sync slash commands. This will call sync_commands in on_connect, and in
1408
1415
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
1409
1416
1410
- ..versionadded:: 2.0
1417
+ .. versionadded:: 2.0
1411
1418
"""
1412
1419
1413
1420
pass
0 commit comments