Skip to content

Spotify Setup

This guide walks you through setting up Spotify authentication for JamBot.

JamBot uses Spotify’s Authorization Code Flow to:

  • Search for songs on Spotify
  • Create playlists from setlists
  • Add songs to playlists
  1. Spotify Account: You need a Spotify account (free or premium)
  2. Spotify Developer App: Create one at the Spotify Developer Dashboard
  1. Go to Spotify Developer Dashboard
  2. Click “Create App”
  3. Fill in the details:
    • App name: JamBot
    • App description: Discord bot for creating jam session playlists
    • Redirect URI: http://localhost:8888/callback
  4. Accept the Terms of Service
  5. Click “Save”
  1. In your app’s dashboard, click “Settings”
  2. Copy your Client ID
  3. Click “View client secret” and copy your Client Secret
  1. Run /jambot-setup in Discord
  2. Enter your Spotify Client ID and Client Secret
  3. Run /jambot-spotify-setup to authorize

Add to your .env file:

Terminal window
SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here
SPOTIFY_REDIRECT_URI=http://localhost:8888/callback

Run the setup script:

Terminal window
python scripts/setup_spotify_auth.py

The script will:

  1. Start a local web server to receive the OAuth callback
  2. Open your browser to authorize JamBot
  3. Exchange the authorization code for tokens
  4. Save tokens to the database
  1. Run /jambot-spotify-setup in Discord
  2. Click the link sent via DM
  3. Authorize JamBot with your Spotify account
  4. Tokens are automatically saved

Check the logs for:

INFO - Spotify authentication successful
INFO - Spotify client initialized for user: your_user_id
  • 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

Problem: You haven’t completed the authorization flow.

Solution: Run /jambot-spotify-setup or python scripts/setup_spotify_auth.py

Problem: Your refresh token has expired.

Solution: Re-authorize by running the setup again.

Solution: Change the redirect URI:

  1. Update your Spotify app settings
  2. Update your .env file
  3. Restart and re-authorize
  • 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