diff options
author | 2022-04-21 20:55:13 +0100 | |
---|---|---|
committer | 2022-04-21 20:55:13 +0100 | |
commit | 6dac5cc1030fa8be9623b95ea6021162c83ce654 (patch) | |
tree | c152cfecff488ad1ac6e26a733a8bc97b71766d9 | |
parent | Merge pull request #65 from python-discord/Add-unqualify-to-the-util-namespace (diff) | |
parent | Load each cog in it's own task (diff) |
Merge pull request #66 from python-discord/load-extensions-in-tasksv6.2.0
Load each cog in it's own task
-rw-r--r-- | botcore/_bot.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/botcore/_bot.py b/botcore/_bot.py index 90de58a5..7902d75d 100644 --- a/botcore/_bot.py +++ b/botcore/_bot.py @@ -11,6 +11,7 @@ from discord.ext import commands from botcore.async_stats import AsyncStatsClient from botcore.site_api import APIClient +from botcore.utils import scheduling from botcore.utils._extensions import walk_extensions from botcore.utils.logging import get_logger @@ -111,11 +112,16 @@ class BotBase(commands.Bot): ) async def load_extensions(self, module: types.ModuleType) -> None: - """Load all the extensions within the given module and save them to ``self.all_extensions``.""" + """ + Load all the extensions within the given module and save them to ``self.all_extensions``. + + This should be ran in a task on the event loop to avoid deadlocks caused by ``wait_for`` calls. + """ + await self.wait_until_guild_available() self.all_extensions = walk_extensions(module) for extension in self.all_extensions: - await self.load_extension(extension) + scheduling.create_task(self.load_extension(extension)) def _add_root_aliases(self, command: commands.Command) -> None: """Recursively add root aliases for ``command`` and any of its subcommands.""" |