Skip to content

Commit

Permalink
refactor: improved the cog loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaacky committed Dec 24, 2024
1 parent f86e4dc commit d133d93
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions chiya/bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import glob
import logging
import os
import sys
from pathlib import Path

import discord
from discord.ext import commands
Expand Down Expand Up @@ -64,10 +64,9 @@ def emit(self, record: logging.LogRecord) -> None:


async def load_cogs():
# TODO: Replace with pathlib
# TODO: Honestly, rewrite this logic, it's so icky
for cog in glob.iglob(os.path.join("cogs", "**", "[!^_]*.py"), root_dir="chiya", recursive=True):
await bot.load_extension(cog.replace("/", ".").replace("\\", ".").replace(".py", ""))
folder = Path(__file__).parent / "cogs"
for file in folder.glob("*.py"):
await bot.load_extension(f"cogs.{file.stem}")
logger.info(f"Cog loaded: {list(bot.cogs.keys())[-1]}")


Expand Down

0 comments on commit d133d93

Please sign in to comment.