-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (61 loc) · 2.12 KB
/
main.py
File metadata and controls
74 lines (61 loc) · 2.12 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
from discord.ext import commands
from discord import app_commands
import discord
import logging
from config import TOKEN
import commands as command_module
import message_edit
import message_delete
import message_reaction
import database
from message_worker import MessageWorker
import forum_sync
from logger_config import setup_logging, get_logger
# Setup logging before anything else
setup_logging()
logger = get_logger(__name__)
intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
intents.messages = True
bot = commands.Bot(command_prefix="!", intents=intents)
forum_sync_handler = forum_sync.setup(bot)
message_worker = MessageWorker(bot, forum_sync_handler)
database.ensure_state_documents()
@bot.event
async def on_ready():
print(f"✅ Logged in as {bot.user.name}")
try:
synced = await bot.tree.sync()
print(f"✅ Synchronized {len(synced)} slash commands")
except Exception as e:
logger.error(f"Error syncing slash commands: {e}")
print("Error synchronizing slash commands:", e)
@bot.event
async def on_message(message):
await message_worker.process_message(message)
await bot.process_commands(message)
@bot.event
async def on_message_edit(before, after):
await message_edit.handle_message_edit(bot, before, after)
@bot.event
async def on_message_delete(message):
await message_delete.handle_message_delete(bot, message)
@bot.event
async def on_raw_reaction_add(payload):
await message_reaction.handle_reaction_add(bot, payload)
@bot.event
async def on_raw_reaction_remove(payload):
await message_reaction.handle_reaction_remove(bot, payload)
@bot.event
async def on_command_error(ctx, error):
logger.error(f"Command error in {ctx.command}: {error}")
if isinstance(error, commands.CommandNotFound):
logger.debug(f"Command not found: {ctx.message.content}")
elif isinstance(error, commands.MissingPermissions):
logger.warning(f"Missing permissions for {ctx.author} in {ctx.guild}: {error}")
else:
logger.error(f"Unexpected command error: {error}")
# Register commands
command_module.setup(bot)
bot.run(TOKEN)