mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Separate loading slash commands from normal commands, split slash commands to separate cogs, make init_extensions support directories
This commit is contained in:
parent
ed0649c953
commit
831459a321
4 changed files with 72 additions and 43 deletions
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue