Files
cogs
database.py
main.py
pterodactyl.py
README.md
requirements.txt
Code
13 1,862
main.py
import asyncio
import logging
import os
import sys
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
logging.basicConfig(
level=getattr(logging, LOG_LEVEL, logging.INFO),
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(sys.stdout),
logging.FileHandler("bot.log", encoding="utf-8"),
],
)
log = logging.getLogger("bot")
COGS = [
"cogs.nodes",
"cogs.account",
"cogs.manage",
"cogs.economy",
"cogs.shop",
"cogs.admin",
"cogs.help",
]
class PteroBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
super().__init__(command_prefix=".", intents=intents, help_command=None)
async def setup_hook(self):
from database import Database
self.db = Database()
await self.db.init()
for cog in COGS:
try:
await self.load_extension(cog)
log.info(f"Loaded cog: {cog}")
except Exception as e:
log.error(f"Failed to load cog {cog}: {e}", exc_info=True)
await self.tree.sync()
log.info("Slash commands synced.")
async def on_ready(self):
log.info(f"Logged in as {self.user} (ID: {self.user.id})")
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="Pterodactyl Panel | .help",
)
)
async def on_command_error(self, ctx: commands.Context, error):
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.MissingRequiredArgument):
embed = discord.Embed(
title="โ Missing Argument",
description=f"Missing required argument: `{error.param.name}`\nUse `.help` to see command usage.",
color=discord.Color.red(),
)
await ctx.send(embed=embed)
return
if isinstance(error, commands.CheckFailure):
embed = discord.Embed(
title="๐ Access Denied",
description="You don't have permission to use this command.",
color=discord.Color.red(),
)
await ctx.send(embed=embed)
return
embed = discord.Embed(
title="โ ๏ธ Error",
description=str(error),
color=discord.Color.red(),
)
await ctx.send(embed=embed)
log.error(f"Command error: {error}", exc_info=True)
async def on_app_command_error(self, interaction: discord.Interaction, error: discord.app_commands.AppCommandError):
embed = discord.Embed(
title="โ ๏ธ Error",
description=str(error),
color=discord.Color.red(),
)
try:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=True)
else:
await interaction.response.send_message(embed=embed, ephemeral=True)
except Exception:
pass
log.error(f"App command error: {error}", exc_info=True)
async def main():
token = os.getenv("DISCORD_TOKEN")
if not token:
log.critical("DISCORD_TOKEN is not set in .env")
sys.exit(1)
async with PteroBot() as bot:
await bot.start(token)
if __name__ == "__main__":
asyncio.run(main())