@@ -409,6 +409,47 @@ def remove_command(
409
409
key = (command , guild_id , type .value )
410
410
return self ._context_menus .pop (key , None )
411
411
412
+ def clear_commands (self , * , guild : Optional [Snowflake ], type : Optional [AppCommandType ] = None ) -> None :
413
+ """Clears all application commands from the tree.
414
+
415
+ This only removes the commands locally -- in order to sync the commands
416
+ and remove them in the client, :meth:`sync` must be called.
417
+
418
+ Parameters
419
+ -----------
420
+ guild: Optional[:class:`~discord.abc.Snowflake`]
421
+ The guild to remove the commands from. If ``None`` then it
422
+ removes all global commands instead.
423
+ type: :class:`~discord.AppCommandType`
424
+ The type of command to clear. If not given or ``None`` then it removes all commands
425
+ regardless of the type.
426
+ """
427
+
428
+ if type is None or type is AppCommandType .chat_input :
429
+ if guild is None :
430
+ self ._global_commands .clear ()
431
+ else :
432
+ try :
433
+ commands = self ._guild_commands [guild .id ]
434
+ except KeyError :
435
+ pass
436
+ else :
437
+ commands .clear ()
438
+
439
+ guild_id = None if guild is None else guild .id
440
+ if type is None :
441
+ self ._context_menus = {
442
+ (name , _guild_id , value ): cmd
443
+ for (name , _guild_id , value ), cmd in self ._context_menus .items ()
444
+ if _guild_id != guild_id
445
+ }
446
+ elif type in (AppCommandType .user , AppCommandType .message ):
447
+ self ._context_menus = {
448
+ (name , _guild_id , value ): cmd
449
+ for (name , _guild_id , value ), cmd in self ._context_menus .items ()
450
+ if _guild_id != guild_id or value != type .value
451
+ }
452
+
412
453
@overload
413
454
def get_command (
414
455
self ,
0 commit comments