40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import discord
|
|
from bot import Groovy
|
|
import config
|
|
import help
|
|
|
|
# Validate configuration before starting
|
|
try:
|
|
config.validate_config()
|
|
config.print_config_info()
|
|
except ValueError as e:
|
|
print(f"❌ Configuration Error:\n{e}")
|
|
print("\n💡 Tip: Copy .env.example to .env and fill in your values")
|
|
exit(1)
|
|
|
|
# Initialize bot with validated config
|
|
client = Groovy(command_prefix=config.get_prefix(), intents=discord.Intents.all())
|
|
|
|
@client.event
|
|
async def on_voice_state_update(member, before, after):
|
|
"""Handle voice state changes - auto-disconnect when alone"""
|
|
if member == client.user:
|
|
return # ignore self actions
|
|
|
|
# get the vc
|
|
voice_client = discord.utils.get(client.voice_clients, guild=member.guild)
|
|
|
|
# if the bot is the only connected member, disconnect
|
|
if voice_client and len(voice_client.channel.members) == 1:
|
|
from cogs.music import queue
|
|
# Clean up the queue
|
|
await queue.clear(member.guild.id)
|
|
await queue.update_server(member.guild.id, False)
|
|
try:
|
|
await voice_client.disconnect(force=True)
|
|
except Exception as e:
|
|
print(f"Error auto-disconnecting: {e}")
|
|
|
|
# Run bot with environment-appropriate token
|
|
client.run(config.get_discord_token())
|