How to Host a High-Performance 24/7 Discord Music Bot with Lavalink v4
Eliminate audio stutter and CPU spikes. Step-by-step setup of Lavalink v4 on Java 21, application.yml audio node configuration, Poru / Wavelink integration, and 24/7 hosting on CoalByte Cloud.

#Why Running Audio Inside Node.js or Python Causes Stutter
Many bot developers initially attempt to stream audio by routing YouTube or Spotify streams directly through FFmpeg and the Node.js/Python main process. This introduces three critical bottlenecks:
- CPU Saturation: Software audio transcoding in high-resolution audio (Opus 48 kHz stereo) maxes out single-thread CPU cycles, delaying slash command responses.
- Memory Leaks: Audio buffer queues in V8 or CPython quickly consume hundreds of megabytes.
- Network Jitter: When home internet speeds fluctuate, Discord voice packets drop, resulting in robotic stuttering audio.
Lavalink v4 solves this by offloading audio decoding, filtering, and voice packet transmission to a standalone, multi-threaded Java 21 audio standalone server.
1. Lavalink v4 Configuration (`application.yml`)
In your audio node root directory, configure application.yml:
server:
port: 2333
address: 0.0.0.0
lavalink:
plugins:
# Lavalink v4 audio source plugins (e.g. YouTube, Spotify)
- dependency: "dev.arbjerg.lavalink.libraries.youtube:youtube-plugin:1.11.4"
repository: "https://maven.lavalink.dev/releases"
server:
password: "YourStrongPassword123!"
playerUpdateInterval: 5 # seconds
bufferDurationMs: 400
frameBufferDurationMs: 5000
opusEncodingQuality: 10
resamplingQuality: HIGH
trackStuckThresholdMs: 10000
useSeekGhosting: true
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
duncteBotSearchEnabled: false
logging:
file:
path: ./logs/lavalink.log
level:
root: INFO
lavalink: INFO2. Connecting with Discord.js via Poru / Kazagumo
import { Client, GatewayIntentBits } from 'discord.js';
import { Poru } from 'poru';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
const nodes = [
{
name: 'CoalByte-Lavalink-EU',
host: '127.0.0.1',
port: 2333,
password: 'YourStrongPassword123!',
secure: false
}
];
export const poru = new Poru(client, nodes, {
library: 'discord.js',
defaultPlatform: 'ytsearch'
});
poru.on('nodeConnect', (node) => {
console.log(`✅ Lavalink Audio Node [${node.name}] successfully connected!`);
});
poru.on('trackStart', (player, track) => {
const channel = client.channels.cache.get(player.textChannel);
channel?.send(`🎶 Now playing: **${track.info.title}** by *${track.info.author}*`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'play') {
const query = interaction.options.getString('query');
const member = interaction.member;
if (!member.voice.channel) {
return interaction.reply({ content: 'Join a voice channel first!', ephemeral: true });
}
await interaction.deferReply();
const player = poru.createConnection({
guildId: interaction.guildId,
voiceChannel: member.voice.channelId,
textChannel: interaction.channelId,
deaf: true
});
const res = await poru.resolve({ query, source: 'ytsearch', requester: interaction.user });
player.queue.add(res.tracks[0]);
if (!player.isPlaying && player.isConnected) player.play();
await interaction.editReply(`Added to queue: **${res.tracks[0].info.title}**`);
}
});
client.login(process.env.DISCORD_TOKEN);3. Deploying 24/7 on CoalByte Free Hosting
With 3 GB dedicated RAM on CoalByte Free Discord Bot Hosting, you have plenty of memory overhead to run both your bot process and Lavalink on the same container without memory starvation or dropouts.
Pregătit să testezi găzduirea 24/7 gratuită?
Pornește propriul tău server cu 3 GB RAM dedicat, 2 vCPU, 8 GB SSD și protecție Anti-DDoS în sub 60 de secunde.
