Skip to content

Spotify links

Needs version 0.11.0 or newer

Spotify links arrived in version 0.11.0 of the bot and its Docker image.

Paste a Spotify track, album or playlist link into play, and the bot reads the song list from Spotify, then plays each song from YouTube: the actual recording, not a music video, live version, cover or sped-up upload, whenever YouTube has it. Spotify podcasts, shows and artist pages aren't supported yet; pasting one gets "Spotify podcasts and artist pages aren't supported yet. Paste a track, album or playlist."

Pasting a Spotify playlist link into /play: the bot finds the playlist with 303 entries, adds them to the queue and starts playing the first song from YouTube

Turning it on

Spotify links are off by default. Turn them on in config.txt:

playback {
  spotify {
    enabled = true
  }
}

If you're updating from an older version and config.txt doesn't have a playback.spotify block yet, the bot adds the new settings for you (off by default, backing up your old file first) the next time it starts. Set enabled = true and restart again.

In a container, set the environment variable instead of editing the file: CONFIG_FORCE_playback_spotify_enabled=true. See Environment variables. The Unraid template turns them on for you.

With it on:

  • Tracks, albums and public playlists work for everyone, with no Spotify account.
  • Private playlists and Liked Songs (spotify:liked) need the bot owner to also turn on Spotify login.
  • A playlist link queues the whole playlist at once, up to maxTracks songs, showing Spotify's song names right away.
  • Spotify links work anywhere a song link works: play, playnext, text commands, saved playlist files and the autoplaylist.

With Spotify off, pasting a Spotify link still gets a reply, "Spotify links are turned off on this bot.", with no setup and no network call.

Note

playback.transforms never sees Spotify links: the bot recognises them before transforms run, whether Spotify is on or off.

How songs are matched

When a song starts playing, or a song is queued behind the one playing, the bot looks one song ahead: if the next queued song is a Spotify one, it starts searching YouTube for it in the background right away, so by the time that song's turn comes up it's usually already found. Only that one song is searched at a time, so pasting a playlist searches for its next song at most, never the whole list.

The bot scores the YouTube results: lengths have to agree, and words like "live", "sped up", "nightcore", "cover", "karaoke" or "instrumental" have to agree with the Spotify title too, not be something the YouTube upload added on its own.

  • A clear best match is used right away. It's then treated exactly like a pasted YouTube link: played from the yt-dlp library if it's already downloaded, offered for download if that's set up, and so on. It isn't saved anywhere; the bot just finds it again the same way next time.
  • A few plausible candidates, none clearly best: see Picking a match below.
  • Nothing close at all: the song is skipped, "Couldn't find Song by Artist on YouTube, skipping."

When someone picks a video from the "pick a match" menu, that choice is remembered (spotify-matches.json, next to the bot: Spotify song ID to YouTube video ID), so the same Spotify song never asks again, on any server, even after a restart. Delete the file to forget every saved pick.

On the now-playing panel and in the queue, the Spotify song's own title, artists and Spotify link show as usual; now-playing adds one small line naming the YouTube video actually playing.

Picking a match

When the bot isn't sure which YouTube video is right, it posts up to 5 candidates in the channel the song was requested from: "Not sure which YouTube video is Song by Artist. Pick one:", with a menu showing each candidate's title, channel and length, tagged when its version differs from Spotify's ("live", "sped up", and so on), plus Skip this song as the last option.

The bot asks which YouTube video is the right one for a Spotify song; the menu lists each candidate's title with its length and channel underneath, one is picked, and the bot plays it for that song

  • Who can pick: the person who queued the song, or a DJ. Anyone else gets "Only the person who queued this song, or a DJ, can pick."
  • Timing: the menu is posted while the song before it is still playing, so it's usually already answered by the time the Spotify song's turn comes up. If a track is pasted on its own with nothing playing, it's asked right away instead, the same as /search.
  • Not answered in time: if nobody picks by the song's turn, or within a minute of the menu being posted if that's later, the song is skipped: "No one picked a match for Song, skipped." The queue moves on.
  • Stopping, skipping or clearing the queue closes any menu that's still open.

Set askWhenUnsure = false to skip unsure songs automatically instead of asking.

Logging in

Turn on playback.spotify.login to let the bot log into a Spotify account, which unlocks that account's private playlists and Liked Songs for everyone using the bot. Use a spare Spotify account, not your main one.

  1. Log into open.spotify.com in a browser, signed in as the spare account.
  2. Open your browser's developer tools (press F12, or right-click the page and choose Inspect), open the Application tab in Chrome or Edge (the Storage tab in Firefox), find Cookies for https://open.spotify.com, and copy the value of sp_dc (it looks something like AQ..., a few hundred characters). Treat it like a password for that account: never share it or paste it anywhere but the bot's own login form.
  3. In Discord, press Log in to Spotify on the button in the bot's DM. If you're the owner, you can also run /spotify login yourself; it's hidden from regular members by Discord's default command permissions, and the bot checks you're the owner again when you submit. Paste the value into the box and submit it.

The browser's developer tools on the Application tab, with Cookies for https://open.spotify.com selected and the sp_dc row highlighted; its value, an example and not a real cookie, is shown in the Cookie Value box below

The bot's DM to its owner: Spotify login is on but the bot isn't logged in, the three steps, and a Log in to Spotify button

The Log in to Spotify form in Discord, with one box labelled sp_dc cookie and a Submit button

The bot tries the cookie with Spotify before saving anything. On success you get "Logged in. Private Spotify playlists and Liked Songs now work."; on failure you get the reason, and nothing is saved. The cookie is kept in spotifycookie.txt, next to the bot, never in config.txt, never echoed back to you, and never shown by debug (which reports only whether the file exists and the current login state). Delete the file to log out.

Without Discord (Docker, Unraid): create spotifycookie.txt yourself, in the same folder as config.txt, containing only the sp_dc value and nothing else. The bot checks for it the next time it needs to log in; no restart required.

If there's no cookie yet, or Spotify starts rejecting the one it has, the bot DMs the owner once with these same steps.

What login unlocks

With login turned on and working, the bot can also load:

  • Private playlists that the logged-in account can see: its own, or ones shared with it as a collaborator.
  • That account's Liked Songs, with spotify:liked.

It does not unlock the private playlists or Liked Songs of whoever happens to run the command: only the bot's own logged-in account's.

Without working login, a private or missing playlist gets "That Spotify playlist is private or doesn't exist. Make it public, or the bot owner can turn on Spotify login."; spotify:liked gets "Liked Songs needs Spotify login, which isn't set up on this bot."

Keeping Spotify working

Spotify occasionally changes details of its web player that this feature depends on. When that happens:

  • A daily, automated check in the MusicBot repository compares the bot's bundled copy of those details against Spotify's current web player and opens a pull request for the project owner to review (or, if it can't find them at all, an issue). It never runs the bot and never logs in anywhere.
  • Once a fix is merged, it ships in the bot's next patch release.
  • If you'd rather not wait for a release, turn on autoUpdate: the bot then checks the MusicBot GitHub repo once a day for newer values and starts using them automatically, within a day of the fix being merged. This only ever talks to GitHub, never Spotify, for this check; a bad or unreachable file is ignored and the bot keeps what it had.

If you've dropped your own spotify-values.json next to the bot as an emergency fix, know that autoUpdate will replace it the first time GitHub's copy has a newer version. The bot logs that it did; it's not silent. Leave autoUpdate off if you want to keep pinning your own file on purpose.

Who can use it

  • Turning Spotify, and Spotify login, on: the bot owner, in config.txt.
  • Playing Spotify links: everyone, once Spotify is turned on.
  • Picking a match, or skipping one: the person who queued the song, or a DJ.
  • /spotify login: the bot owner only.

Settings

All under playback.spotify in config.txt:

Setting Default What it does
playback.spotify.enabled false Turn Spotify links on.
playback.spotify.login false Log into a Spotify account, for private playlists and Liked Songs.
playback.spotify.maxTracks 1000 Most songs to load from one Spotify playlist, album or Liked Songs.
playback.spotify.askWhenUnsure true Ask with a menu when the bot isn't sure which video is right. false skips those songs instead.
playback.spotify.autoUpdate false Fetch updated Spotify values from the MusicBot GitHub repo once a day.

Next: DJ role and permissions.