Files
WellbeingBot
Code
12 739
WellbeingBot/bot.py
import discord
from discord.ext import commands
import os
import logging
from dotenv import load_dotenv
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
log = logging.getLogger("WellbeingBot")
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(
command_prefix="!",
intents=intents,
help_command=None,
activity=discord.Activity(type=discord.ActivityType.listening, name="!help")
)
async def load_cogs():
for filename in os.listdir("cogs"):
if filename.endswith(".py") and not filename.startswith("_"):
try:
await bot.load_extension(f"cogs.{filename[:-3]}")
log.info(f"Loaded cog: {filename[:-3]}")
except Exception as e:
log.error(f"Failed to load cog {filename}: {e}")
@bot.event
async def on_ready():
log.info(f"Logged in as {bot.user} (ID: {bot.user.id})")
log.info(f"Connected to {len(bot.guilds)} guilds")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f"⚠️ Missing argument: {error.param.name}. Use `!help {ctx.command}` for usage.")
return
if isinstance(error, commands.BadArgument):
await ctx.send("⚠️ Invalid argument provided. Check `!help` for correct usage.")
return
log.error(f"Command error in {ctx.command}: {error}")
await ctx.send("❌ An unexpected error occurred. Please try again later.")
@bot.event
async def setup_hook():
await load_cogs()
if __name__ == "__main__":
token = os.getenv("DISCORD_TOKEN")
if not token or token == "your_discord_bot_token_here":
log.error("No valid DISCORD_TOKEN found in .env file")
else:
bot.run(token)