Separate loading slash commands from normal commands, split slash commands to separate cogs, make init_extensions support directories

This commit is contained in:
Stijn De Clercq 2021-09-03 17:57:45 +02:00
parent ed0649c953
commit 831459a321
4 changed files with 72 additions and 43 deletions

View file

@ -47,9 +47,24 @@ class Didier(commands.Bot):
self.load_extension(f"cogs.{ext}")
# Load all remaining cogs
for file in os.listdir("./cogs"):
if file.endswith(".py") and not (file.startswith(self._preload)):
self.load_extension("cogs.{}".format(file[:-3]))
self._init_directory("./cogs")
def _init_directory(self, path: str):
"""
Load all cogs from a directory
"""
# Path to pass into load_extension
load_path = path[2:].replace("/", ".")
for file in os.listdir(path):
# Python file
if file.endswith(".py"):
if not file.startswith(self._preload):
self.load_extension(f"{load_path}.{file[:-3]}")
elif os.path.isdir(new_path := f"{path}/{file}"):
# Subdirectory
# Also walrus operator hype
self._init_directory(new_path)
async def on_ipc_ready(self):
print("IPC server is ready.")