Files
api
cogs
database
bot.py
config.py
requirements.txt
Code
11 654
bot.py
import discord
from discord.ext import commands
import asyncio
import logging
import sys
from config import DISCORD_TOKEN
from api.server import run_api
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(sys.stdout),
logging.FileHandler("bot.log", encoding="utf-8"),
]
)
logger = logging.getLogger("VengeanceBot")
COGS = [
"cogs.setup",
"cogs.verification",
"cogs.lock",
]
class VengeanceBot(commands.Bot):
def __init__(self):
intents = discord.Intents.all()
super().__init__(
command_prefix="!",
intents=intents,
help_command=None,
)
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 globally.")
async def on_ready(self):
logger.info(f"Logged in as {self.user} (ID: {self.user.id})")
logger.info(f"Connected to {len(self.guilds)} guild(s)")
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="for new members | /sendverifypanel"
)
)
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError):
logger.error(f"Command error: {error}")
async def on_app_command_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError):
logger.error(f"App command error in {interaction.command}: {error}")
if not interaction.response.is_done():
await interaction.response.send_message("❌ An unexpected error occurred.", ephemeral=True)
else:
await interaction.followup.send("❌ An unexpected error occurred.", ephemeral=True)
import discord.app_commands as app_commands
async def main():
bot = VengeanceBot()
run_api(bot)
logger.info("API server started in background thread.")
async with bot:
await bot.start(DISCORD_TOKEN)
if __name__ == "__main__":
asyncio.run(main())