-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (57 loc) · 1.82 KB
/
Copy pathmain.py
File metadata and controls
68 lines (57 loc) · 1.82 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
"""Main file for the bot"""
import asyncio
import logging
import os
import discord
from discord.ext import commands
from cogs import CommandHandler, ErrorHandler, LoggingHandler, MusicHandler, QrHandler
logger = logging.getLogger(__name__)
logging.basicConfig()
match os.getenv("LOG_LEVEL"):
case "CRITICAL":
logger.setLevel(logging.CRITICAL)
case "FATAL":
logger.setLevel(logging.FATAL)
case "ERROR":
logger.setLevel(logging.ERROR)
case "WARNING":
logger.setLevel(logging.WARNING)
case "WARN":
logger.setLevel(logging.WARN)
case "INFO":
logger.setLevel(logging.INFO)
case "DEBUG":
logger.setLevel(logging.DEBUG)
case _:
raise f"{os.getenv('LOG_LEVEL')} is invalid"
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
def when_mentioned(bot, msg):
"""
A callable that implements a command prefix equivalent to being mentioned.
"""
return f"<@{bot.user.id}> "
intents = discord.Intents.all()
client = discord.Client(intents=intents)
bot = commands.Bot(intents=intents, command_prefix=when_mentioned)
async def load_cogs():
"""Load all cogs asynchronously."""
await bot.add_cog(CommandHandler(bot))
await bot.add_cog(ErrorHandler(bot))
await bot.add_cog(LoggingHandler(bot))
# await bot.add_cog(MusicHandler(bot))
await bot.add_cog(QrHandler(bot))
@bot.event
async def on_message(message: discord.Message):
"""
Override default message processor to avoid dms
"""
if isinstance(message.channel, discord.DMChannel) and ("!" in message.content):
await message.channel.send("Sorry no dms :wink:")
return
await bot.process_commands(message)
async def main():
async with bot:
await load_cogs()
await bot.start(DISCORD_TOKEN)
if __name__ == "__main__":
asyncio.run(main())