-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (59 loc) · 2.33 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import discord
from discord.ext import commands
import os
import json; data = json.load(open('config.json', 'r'))
import asyncio
import modules.log as log
async def console():
while True:
response = await asyncio.to_thread(input)
if response.startswith('load '):
ext = response[5:]
try:
await bot.load_extension(ext)
print(f'{ext} charged')
except Exception as e:
print(e)
elif response.startswith('unload'):
ext = response[7:]
try:
await bot.unload_extension(ext)
print(f'{ext} dump')
except Exception as e:
print(e)
elif response.startswith('reload '):
ext = response[7:]
try:
await bot.reload_extension(ext)
print(f'{ext} recharged')
except Exception as e:
print(e)
class client(commands.Bot):
def __init__(self):
super().__init__(
command_prefix='$',
intents = discord.Intents.all(),
application_id = data["app_id"]
)
self.initial_extensions = []
types = [dir for dir in os.listdir('cogs') if os.path.isdir(f'cogs/{dir}')]
for type in types:
for root, _, files in os.walk(f"cogs/{type}"):
for file in files:
if file != '__pycache__' and file.endswith('.py'):
if root == f"cogs/{type}":
self.initial_extensions.append(f"cogs.{type}.{file[:-3]}")
else:
dir = os.path.basename(root)
self.initial_extensions.append(f"cogs.{type}.{dir}.{file[:-3]}")
async def setup_hook(self):
log.write('main', 'Debug mode enabled', log.levels.debug)
for ext in self.initial_extensions:
await self.load_extension(ext)
log.write('main', f'{ext} charged', log.levels.debug)
global synced
synced = await bot.tree.sync()
async def on_ready(self):
log.write('main', f'{self.user} is connected with {len(synced)} command(s) synchonizes(s) under version {data["version"]}', log.levels.info)
await asyncio.create_task(console())
bot = client(); bot.run(data["token"])