-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (39 loc) · 1.28 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
# https://www.youtube.com/watch?v=-D2CvmHTqbE
import logging.handlers
import logging
import discord
import asyncio
from discord.ext import commands
from discord import app_commands
import os
from dotenv import dotenv_values
env = dotenv_values(".env")
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=".", intents=intents)
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
logging.getLogger('discord.http').setLevel(logging.WARNING)
handler = logging.handlers.RotatingFileHandler(
filename='discord.log',
encoding='utf-8',
maxBytes=32 * 1024 * 1024, # 32 MiB
backupCount=5, # Rotate through 5 files
)
dt_fmt = '%Y-%m-%d %H:%M:%S'
formatter = logging.Formatter(
'[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
handler.setFormatter(formatter)
logger.addHandler(handler)
discord.utils.setup_logging(handler=handler, formatter=formatter)
@bot.event
async def on_ready():
print("Online")
async def load():
for file in os.listdir("./cogs"):
if file.endswith(".py"):
await bot.load_extension(f"cogs.{file[:-3]}")
async def main():
await load()
await bot.start(env["DISCORD_TOKEN"])
asyncio.run(main())