[commands] Automatically unload top level app commands in extensions

This commit is contained in:
Rapptz
2022-03-12 09:24:26 -05:00
parent a672455ca9
commit 0ef369c0fa
5 changed files with 55 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ from .errors import (
)
from ..errors import ClientException
from ..enums import AppCommandType, InteractionType
from ..utils import MISSING, _get_as_snowflake
from ..utils import MISSING, _get_as_snowflake, _is_submodule
if TYPE_CHECKING:
from ..types.interactions import ApplicationCommandInteractionData, ApplicationCommandInteractionDataOption
@@ -489,6 +489,32 @@ class CommandTree(Generic[ClientT]):
base.extend(cmd for ((_, g, _), cmd) in self._context_menus.items() if g == guild_id)
return base
def _remove_with_module(self, name: str) -> None:
remove: List[Any] = []
for key, cmd in self._context_menus.items():
if cmd.module is not None and _is_submodule(name, cmd.module):
remove.append(key)
for key in remove:
del self._context_menus[key]
remove = []
for key, cmd in self._global_commands.items():
if cmd.module is not None and _is_submodule(name, cmd.module):
remove.append(key)
for key in remove:
del self._global_commands[key]
for mapping in self._guild_commands.values():
remove = []
for key, cmd in mapping.items():
if cmd.module is not None and _is_submodule(name, cmd.module):
remove.append(key)
for key in remove:
del mapping[key]
async def on_error(
self,
interaction: Interaction,