import discord import config import os import asyncio import socket from discord.ext import commands colors = { "default": 0x2b2d31, "error": 0xee281f, "pending": 0xfaa61a } intents = discord.Intents.all() allowed_mentions = discord.AllowedMentions(everyone=False, roles=False, users=True) bot = commands.Bot(command_prefix=['.', ','], intents=intents, allowed_mentions=allowed_mentions) async def load_modules(): for filename in os.listdir('./modules'): if filename.endswith('.py'): try: await bot.load_extension(f'modules.{filename[:-3]}') print(f'Loaded module: {filename}') except Exception as e: print(f'Failed to load module {filename}: {e}') @bot.event async def on_ready(): print(f"Bot is online and running on Python {discord.__version__} & discord.py {discord.__version__}") await bot.change_presence(status=discord.Status.dnd) await bot.tree.sync() print("Commands synced.") @bot.event async def on_message_edit(before, after): await bot.process_commands(after) @bot.event async def on_message(message): if message.author == bot.user: return await bot.process_commands(message) @bot.event async def on_command(ctx): user = ctx.author guild = ctx.guild print(f"{user} [{guild.name}({guild.id})]: {ctx.message.content}") async def start_bot(): await load_modules() while True: try: await bot.start(config.token) except (discord.HTTPException, discord.GatewayNotFound, discord.ConnectionClosed, aiohttp.ClientConnectionError, socket.gaierror) as e: print(f'Error connecting to Discord: {e}. Retrying in 5 seconds...') await asyncio.sleep(5) if __name__ == "__main__": asyncio.run(start_bot())