discord music bot · self-hosted · go · open source

Playback
should survive.

Melodix streams YouTube, SoundCloud and internet radio into your Discord server. A flaky stream, a dead voice connection, a gateway reconnect — these are expected, and it recovers from them instead of dropping the queue. Run it yourself; your server stays independent.

Want to hear it first? It runs in the Ctrl+Z Discord server — join a voice channel and /play something.

[01]why it survives

Every track carries its own fallback chain.

When someone pastes a link, Melodix has to turn that web page into an audio stream it can pipe into a voice channel. The component that does this is called a parser, and YouTube fights it constantly, reshuffling its internals every few weeks. So Melodix keeps a chain of them, ordered fastest-first, and works down the list until one returns a playable stream. The panel beside it is that chain running: the embed your users see, and the log underneath it. Click a parser to see what it does.

ytnative built in-house · zero deps

Melodix's own parser, written specifically for this project. It speaks YouTube's private InnerTube API — the same protocol the official phone and TV apps use — pretending to be the YouTube app on an Apple Vision Pro, which hands back direct audio links with nothing to decrypt. No external programs and no embedded JavaScript engine, just plain HTTP calls from Go. With nothing to decrypt it is the cheapest route, so it is the default. When YouTube changes something, which it will, ytnative tends to fail instantly instead of hanging, and past breakages have been fixed by bumping one client version string.

Melodix BOT Today at 12:32
▶️ Now Playing
youtube ytnative-link 3:32 Rick Astley
melodix · logs

SoundCloud has its own parser, scnative, built on SoundCloud's api-v2. Internet-radio URLs skip straight to ffmpeg, since there is nothing to extract.

[02]when things break

A dropped connection should not end the song.

The chain decides which parser plays a track. The more common failure is different: the track was playing fine, and then the network moved. That is handled in three steps, cheapest first.

  1. Read aheadPlayback runs from a buffer, not straight off the socket, so a stall underneath is absorbed instead of heard. The buffer does not pre-fill, so playback still starts immediately.
  2. Repair in placeWhen the connection is cut, Melodix asks the server for the next byte it had not yet received and carries on. Nothing already downloaded is fetched twice.
  3. Reopen, then switchIf the source is genuinely gone, the same parser reopens at the position it had reached. Only when that fails too does the chain move on.

Discord is covered the same way: a voice reconnect or a gateway drop rejoins and resumes without losing the queue, and the buffer keeps playing while it happens. Queues survive restarts.

[03]self-hosted

The bot you invited can be taken away.

Public music bots are a single point of failure you do not control. Groovy and Rythm were shut down in 2021 at YouTube's request, taking every server's setup with them, and the survivors have added listener caps, queue limits and premium tiers since. Melodix runs under your Discord application, on a machine you already have, with no account to sign up for and nothing phoning home. Nobody can revoke it, meter it, or decide that skipping tracks is now a paid feature.

The trade is real: you are the one keeping it online. That means a machine that stays on, a token you keep secret, and an occasional update when YouTube changes something. In exchange the bot is yours, and it does not disappear.

[04]quick start

Unzip, paste a token, run.

Prebuilt binary

# token from the Discord Developer Portal
  $ unzip melodix-linux-amd64.zip && cd melodix-linux-amd64
  $ nano .env   # DISCORD_TOKEN=…
  $ ./melodix-discord

From source

# Go 1.26 or newer
  $ go build -o melodix-discord ./cmd/discord
  $ DISCORD_TOKEN=your-token ./melodix-discord

The same bundle carries melodix-cli, a terminal player for your own speakers that needs no Discord account. Full setup — bot creation, invite link, every config knob, Docker — lives in docs/running.md.

What you need

required
A Discord bot token and a machine that stays online. One binary, no database server: state is a folder you pick. A small VPS or a Raspberry Pi is plenty, since YouTube playback does no transcoding.
ffmpeg · optional
Only for SoundCloud and internet radio. YouTube's Opus formats go to Discord unchanged, so the common path never touches it.
yt-dlp + a JS runtime · optional
The last parser in the chain, and the one that plays live broadcasts. Keep Node, Deno or Bun on PATH beside it, or live streams fail.
on a thin connection
BUFFER_AHEAD_MS sets how long an interruption can last before anyone hears it. MAX_AUDIO_BITRATE roughly halves bandwidth, since Discord carries 64 kbps anyway unless the server is boosted.
[05]commands

Few commands. Easy to remember.

/playlink, search query, radio URL, or history id
/searchpick from five results instead of the top hit
/queuewhat is playing and what is waiting
/nextskip to the next track
/stopstop playback and clear the queue
/historyrecently played tracks, replayable by id
/helpcommands by category, group, or flat
/settingsenable or disable command groups per server
/maintenanceping, stats, state export
/aboutwhere this bot came from

Every command with its options is in the reference on GitHub.

[06]downloads

Prebuilt binaries.

linux amd64 arm64
windows amd64 arm64
macos amd64 arm64

Not sure which? arm64 is Apple Silicon, Raspberry Pi and ARM cloud instances; amd64 is everything else. Each bundle ships both binaries, a ready-to-edit .env, and the docs. Or run it in Docker.

[07]faq

Questions worth asking first.

Is Melodix free?

Yes. Melodix is open source under the MIT license, with no paid tier, no premium commands and no usage limits. You run it on your own machine with your own Discord token, so the only cost is whatever you already pay for that machine.

Can Melodix play YouTube playlists and mixes?

Yes. Pasting a playlist or mix link expands the whole list into the queue instead of playing only the first video. If the link names a video inside a playlist, that video plays first and the rest of the list follows it.

Does Melodix support Spotify?

No. Melodix plays YouTube, SoundCloud and internet radio. Spotify does not offer a way for a third-party bot to stream its catalogue, so bots that appear to support it are really searching for the same track on YouTube. If that is what you want, paste the track name into /play and you get the same result without the indirection.

Can one instance serve several Discord servers?

Yes. Each server gets its own queue and its own player, so playback in one is unaffected by playback in another. One process handles them all; the limit is the bandwidth and CPU of the machine you run it on.

Where does Melodix store data, and how do I back it up?

In one directory, set by STORAGE_PATH and defaulting to ./data/store. It holds guild settings, the command log and playback history in an embedded write-ahead-logged datastore. Stop the bot and copy the folder; that is the whole backup. The track cache is separate, set by CACHE_DIR, and is safe to delete at any time.

Something not covered here? Ask in the Ctrl+Z server or open an issue on GitHub.