A Discord bot that can search for tracks on Spotify and add them to playlists using slash commands.
- Search for tracks on Spotify with rich embed results
- Add songs to Spotify playlists by searching for the closest match
- Slash command support using Discord.py 2.0+
- OAuth-based Spotify integration for playlist modification
- Environment variable configuration for security
- Automatic command syncing
- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section in the left sidebar
- Click "Add Bot"
- Copy the bot token (you'll need this later)
- Go to Spotify Developer Dashboard
- Click "Create an App"
- Fill in the app name and description
- Important: Add
http://localhost:8888/callbackto the "Redirect URIs" in your app settings - Copy the Client ID and Client Secret (you'll need these later)
pip install -r requirements.txt- Create a
.envfile in the project root - Add the following environment variables:
DISCORD_TOKEN=your_discord_bot_token_here
SPOTIFY_CLIENT_ID=your_spotify_client_id_here
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret_here
SPOTIFY_REDIRECT_URI=http://localhost:8888/callback
DEFAULT_PLAYLIST_ID=your_default_playlist_id_here
Getting your Playlist ID:
- Open Spotify and go to your desired playlist
- Click the "..." menu and select "Share" > "Copy link to playlist"
- The playlist ID is the part after
/playlist/in the URL- Example:
https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M→ ID is37i9dQZF1DXcBWIGoYBM5M
- Example:
- Go to the "OAuth2" > "URL Generator" section in your Discord application
- Select "bot" under scopes
- Select "Send Messages" and "Use Slash Commands" under bot permissions
- Copy the generated URL and open it in your browser to invite the bot
- Run the bot:
python goblin.py - When you first use a Spotify command, you'll need to authorize the bot:
- A browser window will open asking you to log in to Spotify
- Grant the requested permissions
- The authorization will be cached for future use
/hello- The bot will respond with "hello world"/search_track <query>- Search for a track on Spotify and get detailed results with links/add_to_playlist <query> [playlist_id]- Search for a song and add the best match to your playlist with confirmationquery: The song to search for (artist and/or song name)playlist_id: Optional playlist ID. If not provided, uses the DEFAULT_PLAYLIST_ID from .env- New: Shows the found song with confirmation buttons before adding to playlist
/search_track Bohemian Rhapsody Queen
/add_to_playlist Never Gonna Give You Up Rick Astley
/add_to_playlist Shape of You 37i9dQZF1DXcBWIGoYBM5M
When you use /add_to_playlist, the bot will:
- Search for your query and find the best match
- Display the song details (title, artist, album, duration) with album artwork
- Show three buttons:
- ✅ Add to Playlist - Confirms and adds the song
- ❌ Cancel - Cancels without adding anything
- 🔍 Search Again - Suggests trying a more specific search
- The confirmation expires after 60 seconds if no action is taken
This ensures you always get the right song before it's added to your playlist!
- "Spotify API not available": Check your SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET in .env
- "Invalid playlist Id": Verify your playlist ID is correct and accessible
- "Insufficient client scope": Delete the
.spotify_cachefile and re-authorize - Authorization issues: Make sure your redirect URI matches exactly:
http://localhost:8888/callback
Check the console output for detailed error messages and status updates.