feat: Add database setup guide and local configuration files
- Added DATABASE_SETUP.md with comprehensive guide for PostgreSQL and Redis installation on Windows - Created .claude/settings.local.json with permission settings for pytest and database fix scripts - Updated .gitignore to exclude .env.backup file - Included database connection test utilities in lyra/database_setup.py - Added environment variable configuration examples for local development
This commit is contained in:
120
test_discord_bot.py
Normal file
120
test_discord_bot.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""
|
||||
Test Discord bot connection for Lyra AI.
|
||||
|
||||
This script tests if the Discord token is valid and the bot can connect.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
async def test_discord_connection():
|
||||
"""Test Discord bot connection."""
|
||||
print("Testing Discord bot connection...")
|
||||
|
||||
# Get token from environment
|
||||
token = os.getenv('DISCORD_TOKEN')
|
||||
guild_id = os.getenv('DISCORD_GUILD_ID')
|
||||
|
||||
if not token:
|
||||
print("❌ DISCORD_TOKEN not found in .env file")
|
||||
return False
|
||||
|
||||
if token == 'your_discord_token_here':
|
||||
print("❌ Please update DISCORD_TOKEN in .env file with your actual bot token")
|
||||
return False
|
||||
|
||||
print(f"Token starts with: {token[:20]}...")
|
||||
if guild_id:
|
||||
print(f"Guild ID: {guild_id}")
|
||||
|
||||
# Create bot instance
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.guilds = True
|
||||
|
||||
bot = commands.Bot(
|
||||
command_prefix='!lyra ',
|
||||
intents=intents,
|
||||
description="Lyra AI Test Bot"
|
||||
)
|
||||
|
||||
# Test connection
|
||||
connection_successful = False
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
nonlocal connection_successful
|
||||
print(f"✅ Bot connected successfully!")
|
||||
print(f" Bot name: {bot.user.name}")
|
||||
print(f" Bot ID: {bot.user.id}")
|
||||
print(f" Connected to {len(bot.guilds)} server(s)")
|
||||
|
||||
if bot.guilds:
|
||||
for guild in bot.guilds:
|
||||
print(f" - Server: {guild.name} (ID: {guild.id})")
|
||||
|
||||
connection_successful = True
|
||||
await bot.close()
|
||||
|
||||
@bot.event
|
||||
async def on_connect():
|
||||
print("📡 Bot connected to Discord")
|
||||
|
||||
@bot.event
|
||||
async def on_disconnect():
|
||||
print("📡 Bot disconnected from Discord")
|
||||
|
||||
try:
|
||||
print("🔌 Attempting to connect to Discord...")
|
||||
await bot.start(token)
|
||||
return connection_successful
|
||||
|
||||
except discord.LoginFailure:
|
||||
print("❌ Login failed - Invalid bot token")
|
||||
print("💡 Steps to fix:")
|
||||
print(" 1. Go to https://discord.com/developers/applications")
|
||||
print(" 2. Select your application")
|
||||
print(" 3. Go to 'Bot' section")
|
||||
print(" 4. Reset and copy the new token")
|
||||
print(" 5. Update DISCORD_TOKEN in .env file")
|
||||
return False
|
||||
|
||||
except discord.HTTPException as e:
|
||||
print(f"❌ HTTP error: {e}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Connection failed: {e}")
|
||||
return False
|
||||
|
||||
async def main():
|
||||
"""Main test function."""
|
||||
print("=" * 60)
|
||||
print("LYRA AI - DISCORD BOT CONNECTION TEST")
|
||||
print("=" * 60)
|
||||
|
||||
success = await test_discord_connection()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
if success:
|
||||
print("🎉 DISCORD CONNECTION TEST PASSED!")
|
||||
print("Your Discord bot is ready to use!")
|
||||
print("\nNext steps:")
|
||||
print("1. Invite bot to your server (if not already done)")
|
||||
print("2. Run: python -m lyra.main")
|
||||
print("3. Test Lyra in Discord by mentioning her or DMing")
|
||||
else:
|
||||
print("❌ DISCORD CONNECTION TEST FAILED")
|
||||
print("Please check the error messages above and fix the issues")
|
||||
print("=" * 60)
|
||||
|
||||
return success
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
Reference in New Issue
Block a user