-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot_cog.py
45 lines (33 loc) · 1.24 KB
/
bot_cog.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
41
42
43
44
45
import discord
import os
import sys
from discord.ext import commands
# Adiciona em 'sys.path' o diretório da pasta 'discord-bot-py' para não dar erro de
# exportação de módulo em main_bot/cogs/events --> 'from main_bot.cogs.tasks import Tasks'
import re
path = re.match(r"(?P<path>.+)\\", sys.path[0])
sys.path.append(f"{path['path']}")
# ---------------------------------------------------
# Importa as configurações
import settings
bot_token = settings.bot_token()
prefix = settings.prefix()
client = commands.Bot(command_prefix=prefix)
cogs_PATH = f'{sys.path[0]}\cogs'
@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
await ctx.send(f'Ativando o arquivo "{extension}.py"')
@client.command()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
await ctx.send(f'Desativando o arquivo "{extension}.py"')
@client.command()
async def reload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
client.load_extension(f'cogs.{extension}')
await ctx.send(f'Recarregando o arquivo "{extension}.py"')
for filename in os.listdir(cogs_PATH):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
client.run(bot_token)