Added enable and disable to cogs

This commit is contained in:
2022-09-07 22:17:13 +03:00
parent f573d36d42
commit 9d4a6ffc04
2 changed files with 25 additions and 9 deletions

View File

@@ -6,15 +6,18 @@ cog_list: return list of cog filenames
work_with_cogs: loads, reloads and unloads cogs files
"""
import os
import traceback
from os import listdir
from typing import List
from disnake.ext import commands
from .Logger import logger
def cog_list():
async def cog_list(fold='./cogs') -> List[str]:
cogs_list = []
for _filename in listdir('./cogs'):
for _filename in listdir(fold):
if _filename.endswith('.py'):
cogs_list.append(_filename[:-3])
return cogs_list
@@ -44,3 +47,11 @@ async def work_with_cogs(what_do, bot, cog):
elif what_do == 'reload':
bot.reload_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} reloaded')
elif what_do == 'disable':
bot.unload_extension(f'cogs.{_filename}')
os.rename(f'cogs/{_filename}.py', f'cogs/disabled/{_filename}.py')
logger.info(f'Cog {_filename} stopped and disabled')
elif what_do == 'enable':
os.rename(f'cogs/disabled/{_filename}.py', f'cogs/{_filename}.py')
bot.load_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} started and enabled')