-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·55 lines (41 loc) · 1.36 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
#!/usr/bin/env -S venv/bin/python3
import asyncio
import os
from utils.db import init_db
import discord
from discord.ext import tasks
from dotenv import load_dotenv
from utils.error_message import panic
from assets.status_messages import status_messages
load_dotenv()
# Environment variables
bot_token = os.environ.get("bot_token")
owner_id = int(os.environ.get("owner_id", "0"))
init_db()
# The user account
bot = discord.Bot(owner_id=owner_id)
# Extensions to load initially
COGS = [x[:-3] for x in os.listdir("commands") if x.endswith(".py")]
for cog in COGS:
bot.load_extension(f"commands.{cog}")
# Cycle through status messages
@tasks.loop(seconds=20)
async def status():
msg = status_messages[status.current_loop % 4]
msg = msg.format(servers=len(bot.guilds))
await bot.change_presence(activity=discord.Game(msg))
# Send message on unhandled error
@bot.event
async def on_application_command_error(
ctx: discord.ApplicationContext, error: discord.DiscordException
):
await asyncio.sleep(0.15)
if not (isinstance(ctx.options, dict) and ctx.options.get("handled") == True):
await panic(ctx, f"{error}")
# Report when logged in
@bot.event
async def on_ready():
print("✅ Bot logged in")
print(f"ID: {bot.user.id}, Username: {bot.user.name}")
status.start()
bot.run(bot_token)