Skip to content

Commit

Permalink
Load extensions in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Nov 21, 2023
1 parent b154b47 commit 3a6d4ed
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/misobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MPL-2.0
# https://git.joinemm.dev/miso-bot

import asyncio
import traceback
from dataclasses import dataclass
from time import time
Expand Down Expand Up @@ -134,15 +135,22 @@ def register_hooks(self):

async def load_all_extensions(self):
logger.info("Loading extensions...")
for extension in self.extensions_to_load:
tasks = []

async def load(extension):
try:
await self.load_extension(f"cogs.{extension}")
await self.load_extension(extension)
logger.info(f"Loaded [ {extension} ]")
except Exception as error:
logger.error(f"Error loading [ {extension} ]")
traceback.print_exception(type(error), error, error.__traceback__)

await self.load_extension("jishaku")
for extension in self.extensions_to_load:
tasks.append(load(f"cogs.{extension}"))
tasks.append(load("jishaku"))

await asyncio.gather(*tasks)

self.extensions_loaded = True
logger.info("All extensions loaded successfully!")

Expand Down

0 comments on commit 3a6d4ed

Please sign in to comment.