Spotify Setup
This guide walks you through setting up Spotify authentication for JamBot.
Overview
JamBot uses Spotify’s Authorization Code Flow to:
- Search for songs on Spotify
- Create playlists from setlists
- Add songs to playlists
Prerequisites
- Spotify Account: You need a Spotify account (free or premium)
- Spotify Developer App: Create one at the Spotify Developer Dashboard
Step 1: Create a Spotify App
- Go to Spotify Developer Dashboard
- Click “Create App”
- Fill in the details:
- App name: JamBot
- App description: Discord bot for creating jam session playlists
- Redirect URI:
http://localhost:8888/callback
- Accept the Terms of Service
- Click “Save”
Step 2: Get Your Credentials
- In your app’s dashboard, click “Settings”
- Copy your Client ID
- Click “View client secret” and copy your Client Secret
Step 3: Configure the Bot
Option 1: Via Discord Modal (Recommended)
- Run
/jambot-setupin Discord - Enter your Spotify Client ID and Client Secret
- Run
/jambot-spotify-setupto authorize
Option 2: Via Environment Variables
Add to your .env file:
SPOTIFY_CLIENT_ID=your_client_id_hereSPOTIFY_CLIENT_SECRET=your_client_secret_hereSPOTIFY_REDIRECT_URI=http://localhost:8888/callbackStep 4: Authorize Spotify
For Local Development
Run the setup script:
python scripts/setup_spotify_auth.pyThe script will:
- Start a local web server to receive the OAuth callback
- Open your browser to authorize JamBot
- Exchange the authorization code for tokens
- Save tokens to the database
For Production (DigitalOcean)
- Run
/jambot-spotify-setupin Discord - Click the link sent via DM
- Authorize JamBot with your Spotify account
- Tokens are automatically saved
Verify Success
Check the logs for:
INFO - Spotify authentication successfulINFO - Spotify client initialized for user: your_user_idHow Token Refresh Works
- Access tokens expire after 1 hour
- JamBot automatically refreshes tokens using the refresh token
- Refresh tokens are stored in the database
- You shouldn’t need to re-authorize unless:
- You revoke access in Spotify settings
- Your refresh token expires (rare)
- You delete the database
Troubleshooting
”No Spotify tokens found”
Problem: You haven’t completed the authorization flow.
Solution: Run /jambot-spotify-setup or python scripts/setup_spotify_auth.py
”Token refresh failed”
Problem: Your refresh token has expired.
Solution: Re-authorize by running the setup again.
Port 8888 Already in Use
Solution: Change the redirect URI:
- Update your Spotify app settings
- Update your
.envfile - Restart and re-authorize
Security Notes
- Tokens are stored securely in the database
- The database file should be protected with appropriate file permissions
- Never share your tokens or client secret
- Each Discord server can have its own Spotify credentials