aboutsummaryrefslogtreecommitdiffstats
path: root/botcore/utils/_extensions.py
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-03-24 07:44:50 +0000
committerGravatar Chris Lovering <[email protected]>2022-03-24 08:25:27 +0000
commitb8a245061689c45ebee05f27481837576a079e54 (patch)
tree3fdc5c02c810cdb421b20ef5dda66114cb9091c1 /botcore/utils/_extensions.py
parentRemove unneeded kwargs in BotBase (diff)
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.
Diffstat (limited to 'botcore/utils/_extensions.py')
-rw-r--r--botcore/utils/_extensions.py11
1 files changed, 7 insertions, 4 deletions
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)