This guide will help you set up the Discord Prediction Market Bot with Supabase database integration.
- Python 3.8+
- Discord Bot Token
- Supabase Project
- DRIP API Access (for points system)
# Install Python dependencies
pip3 install -r requirements.txt- Go to your Supabase Dashboard
- Navigate to Settings → Database
- Copy the Connection string
- Choose "Transaction pooler" (port 6543) - this is optimal for Discord bots
Example:
postgresql://postgres.zxytvcfgyyzvlhpjffkm:[YOUR-PASSWORD]@aws-0-us-east-2.pooler.supabase.com:6543/postgres
- In your Supabase Dashboard
- Navigate to Settings → API
- Copy the Project URL
Example:
https://zxytvcfgyyzvlhpjffkm.supabase.co
- In Settings → API
- Look for the new API keys section
- Copy both keys:
- Publishable Key:
sb_publishable_... - Secret Key:
sb_secret_...
- Publishable Key:
Note: These are the new format keys. The bot only supports the new keys, not the legacy JWT format.
cp .env.template .env# Environment
ENVIRONMENT=development
DEBUG=true
# Discord Bot
DISCORD_TOKEN=your_actual_discord_bot_token_here
DISCORD_COMMAND_PREFIX=!
DISCORD_SYNC_COMMANDS=true
# Database Configuration
DATABASE_URL=postgresql://postgres.your-ref:your-password@aws-0-us-east-2.pooler.supabase.com:6543/postgres
DATABASE_SUPABASE_URL=https://your-project-ref.supabase.co
DATABASE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_your_actual_key_here
DATABASE_SUPABASE_SECRET_KEY=sb_secret_your_actual_key_here
# DRIP API (your existing points system)
API_API_KEY=your_drip_api_key_here
API_REALM_ID=your_drip_realm_id_hereTest your configuration before proceeding:
# Check for missing environment variables
python3 scripts/validate_config.py --check-env-vars
# Validate full configuration
python3 scripts/validate_config.py --show-summaryYou should see:
✅ All required environment variables are set
✅ Configuration validation successful!
python3 scripts/setup_database.py --test-onlyYou should see:
✅ PostgreSQL connection successful
✅ Supabase API connection successful
python3 scripts/setup_database.pyThis will:
- Create all necessary tables (guilds, predictions, bets, etc.)
- Set up indexes for performance
- Configure triggers and functions
- Enable real-time subscriptions
python3 test_config.pypython3 bot.pyYou should see:
============================================================
CONFIGURATION SUMMARY
============================================================
Environment: development
Debug Mode: True
...
✅ Configuration is ready for use!
Bot is ready! YourBotName
Once your bot is running, test it in Discord:
- Create a prediction:
/predict "Will it rain tomorrow?" "Yes" "No" 24h - Place a bet:
/bet 1 Yes 100 - Check markets:
/markets - Resolve prediction:
/resolve 1 Yes(admin only)
- Check your
.envfile exists and has all required variables - Make sure variable names match exactly (case-sensitive)
- Verify your
DATABASE_URLis correct - Check your Supabase project is active
- Ensure you're using the Transaction Pooler URL (port 6543)
- Verify your
DATABASE_SUPABASE_URLis correct - Check your API keys are the new format (
sb_publishable_...,sb_secret_...) - Make sure your Supabase project has the new API keys enabled
- Ensure your Discord token is at least 50 characters
- Check the token is from the correct bot application
Enable debug mode for detailed logging:
# In your .env file
DEBUG=true
LOG_LEVEL=DEBUG- Check logs: Look at
logs/discord.logfor detailed error messages - Validate config: Run
python3 scripts/validate_config.py --show-summary - Test database: Run
python3 scripts/setup_database.py --test-only
- Debug mode enabled
- Detailed console logging
- Lenient rate limits
- Memory-only caching
- Debug mode disabled
- JSON logging with rotation
- Strict rate limits
- Redis caching recommended
Switch environments by changing:
ENVIRONMENT=production # or development, stagingOnce your bot is running:
- Configure Discord permissions for your bot
- Set up admin roles for prediction resolution
- Configure rate limits based on your server size
- Set up monitoring and logging
- Consider Redis caching for production use
- Never commit your
.envfile to version control - Use environment-specific configurations for different deployments
- Rotate your API keys regularly
- Use the secret key only in secure backend operations
- Enable Row Level Security in Supabase for production
If you encounter issues:
- Check this setup guide
- Review the configuration documentation in
config/README.md - Run the validation scripts to identify specific problems
- Check the logs for detailed error messages