mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
[commands] Automatically unload top level app commands in extensions
This commit is contained in:
@ -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')
|
||||
|
@ -263,6 +263,8 @@ class Cog(metaclass=CogMeta):
|
||||
if cls.__cog_is_app_commands_group__:
|
||||
# Dynamic attribute setting
|
||||
self.__discord_app_commands_group_children__ = children # type: ignore
|
||||
# Enforce this to work even if someone forgets __init__
|
||||
self.module = cls.__module__ # type: ignore
|
||||
|
||||
return self
|
||||
|
||||
|
Reference in New Issue
Block a user