Skip to main content

Lavalink Setup

Lavalink is a standalone audio server that handles music playback for Discord bots. MJ Bot connects to Lavalink to stream music from sources like YouTube, Spotify, SoundCloud, and more.

info

Lavalink is only required if you want to use the music features. If you do not need music, you can skip this page entirely.

Install Java 17+

Lavalink requires Java 17 or higher:

sudo apt update
sudo apt install openjdk-17-jre-headless -y

Verify the installation:

java -version

Create a directory for Lavalink and download the latest release:

mkdir -p ~/lavalink
cd ~/lavalink
curl -L -o Lavalink.jar https://github.com/lavalink-devs/Lavalink/releases/latest/download/Lavalink.jar

Create the Configuration File

Create an application.yml file in the same directory as Lavalink.jar:

~/lavalink/application.yml
server:
port: 2333
address: 0.0.0.0

lavalink:
server:
password: "youshallnotpass"
sources:
youtube: true
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false
bufferDurationMs: 400
frameBufferDurationMs: 5000
youtubePlaylistLoadLimit: 6
playerUpdateInterval: 5
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true

logging:
file:
path: ./logs/
level:
root: INFO
lavalink: INFO
warning

Change the password value to something unique and secure. This password must match the LAVALINK_PASSWORD value in your bot .env file.

Use pm2 to run Lavalink as a background process:

cd ~/lavalink
pm2 start "java -jar Lavalink.jar" --name lavalink
pm2 save

Verify it is running:

pm2 logs lavalink

You should see output indicating Lavalink has started and is listening on port 2333.

Configure the Bot

Update your bot/.env with the Lavalink connection details:

LAVALINK_HOST=localhost
LAVALINK_PORT=2333
LAVALINK_PASSWORD=youshallnotpass

If Lavalink is running on a different server, replace localhost with that server's IP address or hostname.

tip

You can run multiple Lavalink nodes for redundancy. The bot will automatically reconnect if a node goes down, as long as at least one node is available.

Troubleshooting

IssueSolution
Lavalink crashes on startEnsure Java 17+ is installed. Check pm2 logs lavalink for errors.
Bot cannot connect to LavalinkVerify LAVALINK_HOST, LAVALINK_PORT, and LAVALINK_PASSWORD match application.yml.
Port 2333 is blockedOpen the port in your firewall: sudo ufw allow 2333 (only if Lavalink is on a separate server).
No audio in voice channelsMake sure the bot has Connect and Speak permissions in the voice channel.