From ec3012d0b8bf9d53e9316ddb88876149baa274b1 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 21 Apr 2022 20:43:23 +0100 Subject: Load each cog in it's own task --- botcore/_bot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'botcore/_bot.py') 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.""" -- cgit v1.2.3