-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (38 loc) · 1.14 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
"""Initialize the bot"""
import asyncio
import os
import signal
import sys
import discord
from discord.ext import commands
from discord.ext import tasks
from constants import *
from data_config import *
def termination_handler(_signal, _frame): # TODO: ADD EXCEPTION HANDLER
print('Termination signal detected!')
save_all()
sys.exit(0)
signal.signal(signal.SIGINT, termination_handler)
intents = discord.Intents.all()
with open('client.token', 'r') as f:
token = f.readline().strip()
client = commands.Bot(command_prefix=';', help_command=None, intents=intents)
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.do_not_disturb)
await client.tree.sync()
print(f'Bot ready. {VERSION}')
@tasks.loop(minutes=10)
async def save_task():
save_all()
await client.tree.sync()
async def load_cogs():
for file in os.listdir('./cogs'):
if os.fsdecode(file).endswith('.py'):
await client.load_extension(f'cogs.{file[0:-3]}')
async def main():
save_task.start()
await load_cogs()
await client.start(token)
if __name__ == '__main__':
asyncio.run(main())