From b8a245061689c45ebee05f27481837576a079e54 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 24 Mar 2022 07:44:50 +0000 Subject: Provide a bot.all_extensions instance attribute This allows commands like extensions and source to see all of the available commands, rather than just the currently loaded commands. --- botcore/utils/_extensions.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'botcore/utils/_extensions.py') diff --git a/botcore/utils/_extensions.py b/botcore/utils/_extensions.py index 6848fae6..d90a25dd 100644 --- a/botcore/utils/_extensions.py +++ b/botcore/utils/_extensions.py @@ -22,19 +22,20 @@ def unqualify(name: str) -> str: def walk_extensions(module: types.ModuleType) -> frozenset[str]: """ - Yield extension names from the given module. + Return all extension names from the given module. Args: module (types.ModuleType): The module to look for extensions in. Returns: - An iterator object, that returns a string that can be passed directly to - :obj:`discord.ext.commands.Bot.load_extension` on call to next(). + A set of strings that can be passed directly to :obj:`discord.ext.commands.Bot.load_extension`. """ def on_error(name: str) -> NoReturn: raise ImportError(name=name) # pragma: no cover + modules = set() + for module_info in pkgutil.walk_packages(module.__path__, f"{module.__name__}.", onerror=on_error): if unqualify(module_info.name).startswith("_"): # Ignore module/package names starting with an underscore. @@ -46,4 +47,6 @@ def walk_extensions(module: types.ModuleType) -> frozenset[str]: # If it lacks a setup function, it's not an extension. continue - yield module_info.name + modules.add(module_info.name) + + return frozenset(modules) -- cgit v1.2.3