-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (67 loc) · 2.2 KB
/
app.py
File metadata and controls
78 lines (67 loc) · 2.2 KB
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
75
76
77
78
import discord
import asyncio
import sqlite3 as sql
import sys
import os
from loguru import logger
from dotenv import load_dotenv
from discord.ext import commands
from discord import embeds, guild, client, Intents
os.makedirs("databases", exist_ok=True)
logger.remove()
logger.add(
sys.stdout,
format="<black><bg white> {time:HH:mm:ss} </bg white></black><black><bg green> {level} </bg green></black> {message}",
level="INFO",
colorize=True
)
logger.add(
sys.stdout,
format="<black><bg white> {time:HH:mm:ss} </bg white></black><black><bg #FFA500> {level} </bg #FFA500></black> {message}",
level="WARNING",
colorize=True
)
logger.add(
sys.stdout,
format="<black><bg white> {time:HH:mm:ss} </bg white></black><black><bg red> {level} </bg red></black> {message}",
level="ERROR",
colorize=True
)
conn = sql.connect('databases/economy.db')
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS economy (
user_id INTEGER PRIMARY KEY,
balance INTEGER DEFAULT 0
)
""")
conn.commit()
env_path = os.path.dirname(os.path.abspath(__file__))
load_dotenv(os.path.join(env_path, ".env"))
intents = discord.Intents.all()
activity = discord.Activity(type=discord.ActivityType.watching, name="DaggerNodes host now!")
client = commands.Bot(command_prefix='dn!', help_command=None, activity=activity, intents=intents)
client.conn = conn
client.cursor = cursor
@client.event
async def on_ready():
try:
synced_commands = await client.tree.sync()
logger.info(f'Successfully synced {len(synced_commands)} commands.')
except Exception as error:
pass
logger.info("{0.user} bot is now online".format(client))
async def load_cogs():
for root, dirs, files in os.walk("cogs"):
for file in files:
if file.endswith(".py"):
path = os.path.join(root, file).replace("/", ".").replace("\\", ".")[:-3]
try:
await client.load_extension(path)
except Exception as error:
logger.error(f'Failed to load {path} error stack: {error}')
async def main():
async with client:
await load_cogs()
await client.start(os.getenv("TOKEN"))
asyncio.run(main())