[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

@ -38,6 +38,7 @@ from typing import Any, Callable, Mapping, List, Dict, TYPE_CHECKING, Optional,
import discord
from discord import app_commands
from discord.app_commands.tree import _retrieve_guild_ids
from discord.utils import MISSING, _is_submodule
from .core import GroupMixin
from .view import StringView
@ -65,8 +66,6 @@ __all__ = (
'AutoShardedBot',
)
MISSING: Any = discord.utils.MISSING
T = TypeVar('T')
CFT = TypeVar('CFT', bound='CoroFunc')
CXT = TypeVar('CXT', bound='Context')
@ -120,10 +119,6 @@ def when_mentioned_or(*prefixes: str) -> Callable[[Union[Bot, AutoShardedBot], M
return inner
def _is_submodule(parent: str, child: str) -> bool:
return parent == child or child.startswith(parent + ".")
class _DefaultRepr:
def __repr__(self):
return '<default-help-command>'
@ -724,6 +719,9 @@ class BotBase(GroupMixin):
for index in reversed(remove):
del event_list[index]
# remove all relevant application commands from the tree
self.__tree._remove_with_module(name)
def _call_module_finalizers(self, lib: types.ModuleType, key: str) -> None:
try:
func = getattr(lib, 'teardown')