forked from cibere/discord-bot-made-with-no-communication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
40 lines (30 loc) · 1.31 KB
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import logging
import os
import pathlib
import discord
import discord.ext.commands.errors
from discord.ext import commands
class Handler:
def __init__(self, client: commands.Bot):
self._bot = client
self._cwd = pathlib.Path.cwd()
self.name = os.path.basename(__file__)
self.logger = logging.getLogger()
async def cog_auto_loader(self, reload=False):
"""This will load all Cogs inside of the cogs folder."""
path = f'cogs' # This gets us to the folder for the module specific scripts to load via the cog.
try:
cog_file_list = pathlib.Path.joinpath(self._cwd, 'cogs').iterdir()
for script in cog_file_list:
if script.name.endswith('.py'):
cog = f'{path}.{script.name[:-3]}'
try:
if reload:
await self._bot.reload_extension(cog)
else:
await self._bot.load_extension(cog)
self.logger.info(f'**SUCCESS** {self.name} Loading Cog **{cog}**')
except commands.errors.ExtensionAlreadyLoaded:
continue
except FileNotFoundError as e:
self.logger.error(f'**ERROR** Loading Cog ** - File Not Found {e}')