Amber/main.py

55 lines
1.4 KiB
Python
Raw Normal View History

import os
import logging
2025-01-18 21:45:25 -05:00
import discord
from dotenv import load_dotenv
from commands import setup_commands
2025-01-18 21:45:25 -05:00
# Load environment variables
2025-01-18 21:45:25 -05:00
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD_ID = os.getenv("GUILD_ID")
# Validate Guild ID
if GUILD_ID:
try:
GUILD_ID = int(GUILD_ID)
except ValueError:
logging.error("Invalid GUILD_ID in .env file. It must be a numeric value.")
GUILD_ID = None
2025-01-18 21:45:25 -05:00
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
intents.guilds = True
intents.voice_states = True
class AmberClient(discord.Client):
def __init__(self):
super().__init__(intents=intents)
self.tree = discord.app_commands.CommandTree(self)
async def on_ready(self):
logging.info(f"Amber is online as {self.user}")
2025-01-18 21:45:25 -05:00
# Sync commands after the bot is fully ready
if GUILD_ID:
logging.info(f"Setting up commands for guild: {GUILD_ID}")
else:
logging.info("Setting up global commands (no guild ID specified).")
2025-01-18 21:45:25 -05:00
try:
await setup_commands(self, guild_id=GUILD_ID)
except Exception as e:
logging.error(f"Failed to setup commands: {e}")
2025-01-18 21:45:25 -05:00
logging.basicConfig(level=logging.INFO)
client = AmberClient()
if TOKEN:
client.run(TOKEN)
else:
logging.error("Bot token not found. Check your .env file.")