Skip to content

williamkohler/goblin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Bot with Spotify Integration

A Discord bot that can search for tracks on Spotify and add them to playlists using slash commands.

Features

  • 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

Setup Instructions

1. Create a Discord Application

  1. Go to Discord Developer Portal
  2. Click "New Application" and give it a name
  3. Go to the "Bot" section in the left sidebar
  4. Click "Add Bot"
  5. Copy the bot token (you'll need this later)

2. Create a Spotify Application

  1. Go to Spotify Developer Dashboard
  2. Click "Create an App"
  3. Fill in the app name and description
  4. Important: Add http://localhost:8888/callback to the "Redirect URIs" in your app settings
  5. Copy the Client ID and Client Secret (you'll need these later)

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment

  1. Create a .env file in the project root
  2. 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:

  1. Open Spotify and go to your desired playlist
  2. Click the "..." menu and select "Share" > "Copy link to playlist"
  3. The playlist ID is the part after /playlist/ in the URL
    • Example: https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M → ID is 37i9dQZF1DXcBWIGoYBM5M

5. Invite Bot to Your Server

  1. Go to the "OAuth2" > "URL Generator" section in your Discord application
  2. Select "bot" under scopes
  3. Select "Send Messages" and "Use Slash Commands" under bot permissions
  4. Copy the generated URL and open it in your browser to invite the bot

6. First Run & Spotify Authorization

  1. Run the bot: python goblin.py
  2. 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

Usage

Available Commands:

  • /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 confirmation
    • query: 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

Examples:

/search_track Bohemian Rhapsody Queen
/add_to_playlist Never Gonna Give You Up Rick Astley
/add_to_playlist Shape of You 37i9dQZF1DXcBWIGoYBM5M

How Song Confirmation Works:

When you use /add_to_playlist, the bot will:

  1. Search for your query and find the best match
  2. Display the song details (title, artist, album, duration) with album artwork
  3. Show three buttons:
    • ✅ Add to Playlist - Confirms and adds the song
    • ❌ Cancel - Cancels without adding anything
    • 🔍 Search Again - Suggests trying a more specific search
  4. 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!

Troubleshooting

Common Issues:

  1. "Spotify API not available": Check your SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET in .env
  2. "Invalid playlist Id": Verify your playlist ID is correct and accessible
  3. "Insufficient client scope": Delete the .spotify_cache file and re-authorize
  4. Authorization issues: Make sure your redirect URI matches exactly: http://localhost:8888/callback

Logs:

Check the console output for detailed error messages and status updates.

About

Goblin - A Discord bot for creating and sharing curated lists on Spotify and Letterboxd. Quickly build and distribute music playlists and movie watchlists through simple Discord commands, making it easy to share your recommendations with friends and communities.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages