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.
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
Download Lavalink
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:
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
Change the password value to something unique and secure. This password must match the LAVALINK_PASSWORD value in your bot .env file.
Start Lavalink with pm2
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.
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
| Issue | Solution |
|---|---|
| Lavalink crashes on start | Ensure Java 17+ is installed. Check pm2 logs lavalink for errors. |
| Bot cannot connect to Lavalink | Verify LAVALINK_HOST, LAVALINK_PORT, and LAVALINK_PASSWORD match application.yml. |
| Port 2333 is blocked | Open the port in your firewall: sudo ufw allow 2333 (only if Lavalink is on a separate server). |
| No audio in voice channels | Make sure the bot has Connect and Speak permissions in the voice channel. |