-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
58 lines (49 loc) · 1.93 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
56
57
58
"""
This module contains the main class for the bot, which sets up the bot with intents, loads the contributors, emoji dicts,
and posted events, loads the cogs, sets up commands and events for the bot, and then starts the bot.
"""
import discord
import os
import asyncio
from discord.ext import commands
from tasks.tasks import TaskManager
from utils.utils import Utils
from cogs.contributors import ContributorCommandsCog
from cogs.events import EventsCog
from cogs.help import HelpCommandCog
from cogs.gov import GovCommandsCog
from database.service import DatabaseService
from logger.logger import logger
class Bot:
def __init__(self):
self.bot = commands.Bot(command_prefix="/", intents=discord.Intents.all())
db_service = DatabaseService()
self.bot.ongoing_votes = db_service.get_ongoing_votes()
@self.bot.event
async def on_ready():
logger.info(f"Logged in as {self.bot.user.name} ({self.bot.user.id})")
await self.setup_cogs()
await self.bot.tree.sync()
await TaskManager.start_tasks(self.bot)
async def setup_cogs(self):
"""Setup cogs after bot is ready"""
try:
await self.bot.add_cog(ContributorCommandsCog(self.bot))
await self.bot.add_cog(EventsCog(self.bot))
await self.bot.add_cog(GovCommandsCog(self.bot))
logger.info("Cogs loaded successfully")
except Exception as e:
logger.error(f"Error loading cogs: {e}")
raise
async def main(self):
try:
discord_token = os.getenv("DISCORD_BOT_TOKEN")
if not discord_token:
raise ValueError("DISCORD_BOT_TOKEN environment variable is not set")
await self.bot.start(discord_token)
except Exception as e:
logger.error(f"An error occurred in main: {e}")
raise
if __name__ == "__main__":
bot = Bot()
asyncio.run(bot.main())