Files
cogs
api.py
bot.py
config.py
requirements.txt
Code
8 560
bot.py
import discord
from discord.ext import commands
import logging
import asyncio
from config import DISCORD_TOKEN, API_BASE_URL, API_KEY
from api import TiersAPIClient
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
COGS = [
"cogs.profile",
"cogs.elo",
"cogs.skin",
"cogs.admin",
]
class MinecraftTiersBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
super().__init__(command_prefix="!", intents=intents)
self.api = TiersAPIClient(API_BASE_URL, API_KEY)
async def setup_hook(self):
for cog in COGS:
try:
await self.load_extension(cog)
logger.info(f"Loaded cog: {cog}")
except Exception as e:
logger.error(f"Failed to load cog {cog}: {e}")
await self.tree.sync()
logger.info("Slash commands synced.")
async def close(self):
await self.api.close()
await super().close()
async def on_ready(self):
logger.info(f"Logged in as {self.user} (ID: {self.user.id})")
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="Minecraft Tiers | /register",
)
)
async def on_app_command_error(
self, interaction: discord.Interaction, error: discord.app_commands.AppCommandError
):
logger.error(f"Unhandled app command error: {error}")
msg = "❌ An unexpected error occurred. Please try again later."
if interaction.response.is_done():
await interaction.followup.send(msg, ephemeral=True)
else:
await interaction.response.send_message(msg, ephemeral=True)
async def main():
bot = MinecraftTiersBot()
async with bot:
await bot.start(DISCORD_TOKEN)
if __name__ == "__main__":
asyncio.run(main())