@@ -238,54 +238,52 @@ async def register_commands(self) -> None:
238
238
registered_commands_dict = {cmd ["name" ]:cmd for cmd in registered_commands }
239
239
global_pending_application_commands_dict = {}
240
240
241
- if len (registered_commands ) > 0 :
242
- for command in [
243
- cmd for cmd in self .pending_application_commands if cmd .guild_ids is None
244
- ]:
245
- as_dict = command .to_dict ()
246
-
247
- global_pending_application_commands_dict [command .name ] = as_dict
248
- if command .name in registered_commands_dict :
249
- match = registered_commands_dict [command .name ]
250
- else :
251
- match = None
252
- # TODO: There is probably a far more efficient way of doing this
253
- # We want to check if the registered global command on Discord servers matches the given global commands
254
- if match :
255
- as_dict ["id" ] = match ["id" ]
256
-
257
- keys_to_check = {"default_permission" : True , "name" : True , "description" : True , "options" : ["type" , "name" , "description" ]}
258
- for key , more_keys in {
259
- key :more_keys
260
- for key , more_keys in keys_to_check .items ()
261
- if key in as_dict .keys ()
262
- if key in match .keys ()
263
- }.items ():
264
- if key == "options" :
265
- for i , option_dict in enumerate (as_dict [key ]):
266
- for key2_change in [
267
- key2
268
- for key2 in more_keys
269
- if key2 in option_dict .keys () and key2 in match [key ][i ].keys ()
270
- if option_dict [key2 ] != match [key ][i ][key2 ]
271
- ]:
272
- print (f"A change in the '{ key2_change } ' property of '{ key } ' in the '{ command .name } ' global command was noticed, will send to Discord to update" )
273
- needs_bulk = True
274
- else :
275
- if as_dict [key ] != match [key ]:
276
- print (f"A change in the '{ key } ' property of '{ command .name } ' global command was noticed, will send to Discord to update" )
241
+ for command in [
242
+ cmd for cmd in self .pending_application_commands if cmd .guild_ids is None
243
+ ]:
244
+ as_dict = command .to_dict ()
245
+
246
+ global_pending_application_commands_dict [command .name ] = as_dict
247
+ if command .name in registered_commands_dict :
248
+ match = registered_commands_dict [command .name ]
249
+ else :
250
+ match = None
251
+ # TODO: There is probably a far more efficient way of doing this
252
+ # We want to check if the registered global command on Discord servers matches the given global commands
253
+ if match :
254
+ as_dict ["id" ] = match ["id" ]
255
+
256
+ keys_to_check = {"default_permission" : True , "name" : True , "description" : True , "options" : ["type" , "name" , "description" ]}
257
+ for key , more_keys in {
258
+ key :more_keys
259
+ for key , more_keys in keys_to_check .items ()
260
+ if key in as_dict .keys ()
261
+ if key in match .keys ()
262
+ }.items ():
263
+ if key == "options" :
264
+ for i , option_dict in enumerate (as_dict [key ]):
265
+ for key2_change in [
266
+ key2
267
+ for key2 in more_keys
268
+ if key2 in option_dict .keys () and key2 in match [key ][i ].keys ()
269
+ if option_dict [key2 ] != match [key ][i ][key2 ]
270
+ ]:
271
+ # When a property in the options of a pending global command is changed
277
272
needs_bulk = True
278
- else :
279
- print (f"A pending global command '{ command .name } ' is not registered in Discord servers, will send to Discord to update" )
280
- needs_bulk = True
273
+ else :
274
+ if as_dict [key ] != match [key ]:
275
+ # When a property in a pending global command is changed
276
+ needs_bulk = True
277
+ else :
278
+ # When a name of a pending global command is not registered in Discord
279
+ needs_bulk = True
281
280
282
- commands_to_bulk .append (as_dict )
281
+ commands_to_bulk .append (as_dict )
283
282
284
- if len (registered_commands_dict ) > 0 :
285
- for name , command in registered_commands_dict .items ():
286
- if not name in global_pending_application_commands_dict .keys ():
287
- print (f"A registered global command '{ name } ' is not found in the pending global commands, will send to Discord to update" )
288
- needs_bulk = True
283
+ for name , command in registered_commands_dict .items ():
284
+ if not name in global_pending_application_commands_dict .keys ():
285
+ # When a registered global command is not available in the pending global commands
286
+ needs_bulk = True
289
287
290
288
if needs_bulk :
291
289
commands = await self .http .bulk_upsert_global_commands (self .user .id , commands_to_bulk )
0 commit comments