Hosting a Discord music bot: Lavalink, resources and rules
What you need to run a Discord music bot: voice libraries, FFmpeg, Lavalink, how much memory and CPU to give it, and content and terms of service to consider.
Updated · 3 min read
Music bots are the most resource-hungry kind of Discord bot. They need voice support in your library, audio encoding, and often a separate audio server called Lavalink. They also come with content and terms-of-service questions you should think about before you build one.
How Discord music bots work
To play audio, a bot joins a voice channel, fetches audio from a source, encodes it to Opus and streams it to Discord. There are two common designs:
| Approach | How it works | Trade-offs |
|---|---|---|
| In-process audio | The bot itself decodes and encodes audio, usually with FFmpeg | Simple setup, but uses the bot's own CPU and memory |
| Lavalink | A separate Java audio server does the heavy lifting; your bot controls it through a client library | Scales better, but you have to run and connect to the Lavalink server |
In-process audio
discord.js
You need @discordjs/voice, an Opus encoder and an encryption library, plus FFmpeg for most sources. Check the discord.js guide for the current list of required packages, since voice requirements change over time. The ffmpeg-static npm package bundles an FFmpeg binary so you don't depend on one being installed on the system.
Voice also needs the GuildVoiceStates intent:
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
});
discord.py
Install the voice extra and make sure FFmpeg is available:
discord.py[voice]>=2.4
discord.FFmpegPCMAudio and FFmpegOpusAudio call the ffmpeg executable, so it must be on the server's path or you need to point to a binary. Check whether ffmpeg is available in your server before building around it.
Keep voice libraries up to date. Discord changes its voice protocol requirements from time to time, and outdated versions can stop connecting.
Lavalink
Lavalink is a standalone Java application. Your bot connects to it with a client library such as Shoukaku, Riffy or lavalink-client (Node.js), or Wavelink or lavalink.py (Python).
Things to know:
- Lavalink needs a recent Java runtime and typically wants several hundred MB to 1 GB or more of memory on its own, depending on the number of players.
- Schokr's generic runtimes are Node.js, Bun and Python, so a common setup is to run your bot on Schokr and connect it to a Lavalink node you run elsewhere or one offered by a provider. Put the node's host, port and password in your
.envfile. - Lavalink and its source plugins change often. Follow the official documentation for the version you install.
Resource needs
| Setup | Suggested memory | CPU |
|---|---|---|
| Small in-process bot, one or two servers | 512 MB to 1 GB | Encoding uses noticeable CPU while playing |
| Bot connected to an external Lavalink | 256 to 512 MB for the bot itself | Low; Lavalink does the work |
Your team pool has 1.5 cores in total, so a music bot playing in many servers at once can starve your other servers. Give it its own server with a fair CPU share. See multiple bots on one team.
Content and terms of service
Think about where your audio comes from:
- Many streaming platforms, including YouTube, prohibit downloading or rebroadcasting their content outside their own players in their terms of service. Several large public music bots shut down after legal pressure.
- Playing audio you don't have rights to can expose you to takedowns, and your bot to action from Discord.
- Safer sources include music you own or have licensed, royalty-free or Creative Commons libraries, internet radio streams that allow it, and services with official APIs that permit this use.
Read the terms of every source you integrate and keep public bots to sources you're allowed to use.
Troubleshooting
- Bot joins but plays nothing: FFmpeg missing, a missing encryption or Opus package, or an outdated voice library. Check the console for errors.
- Audio stutters: CPU is maxed out. Check the Resources view and give the server more CPU, or move to Lavalink.
- Lavalink connection refused: wrong host, port or password, or the node isn't reachable from the internet.