Skip to content

Commit d133d93

Browse files
committed
refactor: improved the cog loading
1 parent f86e4dc commit d133d93

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

chiya/bot.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
2-
import glob
32
import logging
43
import os
54
import sys
5+
from pathlib import Path
66

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

6565

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

7372

0 commit comments

Comments
 (0)