Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 83fae4f

Browse files
committed
Add CommandTree.clear_commands
1 parent 8a1800b commit 83fae4f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

discord/app_commands/tree.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,47 @@ def remove_command(
409409
key = (command, guild_id, type.value)
410410
return self._context_menus.pop(key, None)
411411

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+
412453
@overload
413454
def get_command(
414455
self,

0 commit comments

Comments
 (0)