Files
cogs
.gitignore
bot.py
database.py
embeds.py
logging_service.py
permissions.py
README.md
requirements.txt
Code
17 1,501
bot.py
from __future__ import annotations
import logging
import os
import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv
from cogs.activity import Activity
from cogs.applications import Applications, ApplyView
from cogs.configuration import Configuration
from cogs.loa import LOA
from cogs.moderation import Moderation
from cogs.staff import Staff
from cogs.roleplay import Dispatch, Economy, Roleplay, Shift
from cogs.tickets import Tickets
from database import Database
from embeds import error
load_dotenv()
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
class MapleCountyBot(commands.Bot):
def __init__(self) -> None:
intents = discord.Intents.default()
intents.members = True
super().__init__(command_prefix="!", intents=intents)
self.db = Database()
async def setup_hook(self) -> None:
for cog in (Staff, Activity, LOA, Applications, Moderation, Configuration, Roleplay, Economy, Shift, Dispatch, Tickets):
await self.add_cog(cog(self))
self.add_view(ApplyView(self.get_cog("Applications")))
dev_guild = os.getenv("DEV_GUILD_ID")
if dev_guild:
guild = discord.Object(id=int(dev_guild))
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
logging.info("Slash commands synced to development guild %s", dev_guild)
else:
await self.tree.sync()
logging.info("Global slash commands synced")
async def on_ready(self) -> None:
logging.info("Logged in as %s (%s)", self.user, self.user.id if self.user else "unknown")
async def on_app_command_error(self, interaction: discord.Interaction, error_: app_commands.AppCommandError) -> None:
logging.error("Slash command failed", exc_info=error_)
message = "Something went wrong while processing that command. Check the bot logs for details."
if isinstance(error_, app_commands.CommandOnCooldown):
message = f"Please try again in {error_.retry_after:.1f} seconds."
if interaction.response.is_done():
await interaction.followup.send(embed=error(message), ephemeral=True)
else:
await interaction.response.send_message(embed=error(message), ephemeral=True)
bot = MapleCountyBot()
token = os.getenv("DISCORD_TOKEN")
if not token:
raise RuntimeError("DISCORD_TOKEN is missing. Copy .env.example to .env and set it.")
bot.run(token)