Hosting a Discord Music Bot on a VPS: Complete Setup Guide

Published on

How to run a Discord music bot 24/7 on a VPS. Covers bot frameworks, audio libraries, deployment, and performance tuning for multiple servers.

Written by Space-Node Team – Infrastructure Team – 15+ years combined experience in game server hosting, VPS infrastructure, and 24/7 streaming solutions. Read author bio →

Running a Discord music bot from your computer means it goes offline when you shut down. A VPS keeps your bot live 24/7 for your community.

Bot Framework Choices

discord.js + @discordjs/voice (Node.js)

Most popular for JavaScript developers:

const { Client, GatewayIntentBits } = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');

const client = new Client({
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates]
});

discord.py + wavelink (Python)

Python alternative with good audio library support:

import discord
import wavelink

class MusicBot(discord.Bot):
    async def on_ready(self):
        print(f'Bot ready: {self.user}')

Lavalink (Java)

Dedicated audio server that handles audio processing separately from your bot. Best for bots serving many servers simultaneously.

Node.js Music Bot Setup

Install Dependencies

npm init -y
npm install discord.js @discordjs/voice @discordjs/opus sodium-native ytdl-core

Basic Bot Structure

const { Client, GatewayIntentBits } = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const ytdl = require('ytdl-core');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ]
});

const queue = new Map();

client.on('interactionCreate', async interaction => {
    if (!interaction.isChatInputCommand()) return;
    
    if (interaction.commandName === 'play') {
        const channel = interaction.member.voice.channel;
        if (!channel) {
            return interaction.reply('Join a voice channel first!');
        }
        
        const url = interaction.options.getString('url');
        const connection = joinVoiceChannel({
            channelId: channel.id,
            guildId: interaction.guildId,
            adapterCreator: interaction.guild.voiceAdapterCreator
        });
        
        const player = createAudioPlayer();
        const stream = ytdl(url, { filter: 'audioonly', quality: 'highestaudio' });
        const resource = createAudioResource(stream);
        
        player.play(resource);
        connection.subscribe(player);
        
        await interaction.reply('Now playing!');
    }
});

client.login('YOUR_BOT_TOKEN');

Deployment on VPS

Process Management with PM2

npm install -g pm2
pm2 start bot.js --name "music-bot"
pm2 startup    # Auto-start on reboot
pm2 save       # Save process list

systemd Alternative

Create /etc/systemd/system/music-bot.service:

[Unit]
Description=Discord Music Bot
After=network.target

[Service]
Type=simple
User=botuser
WorkingDirectory=/home/botuser/music-bot
ExecStart=/usr/bin/node bot.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

Resource Requirements

| Scale | CPU | RAM | Plan | |-------|-----|-----|------| | 1-5 servers | 1 core | 512MB-1GB | Discord Bot Small (Free) | | 5-20 servers | 1 core | 1-2GB | Discord Bot Middle (€3/6mo) | | 20-100 servers | 2 cores | 2-4GB | Discord Bot Large (€6/6mo) | | 100+ servers | VPS | 4-8GB | VPS plan |

Space-Node's Discord Bot hosting starts free and scales with your bot's growth.

Audio Quality Tips

Opus Encoding

Discord uses Opus codec. Install native Opus for best quality:

npm install @discordjs/opus
# or
npm install opusscript  # Fallback (slower)

Native @discordjs/opus uses significantly less CPU than the JavaScript fallback.

Buffer Management

Audio stuttering indicates buffer underrun:

const resource = createAudioResource(stream, {
    inlineVolume: true,
    inputType: StreamType.Arbitrary
});
resource.volume.setVolume(0.5);

Memory Management

Music bots can leak memory through unreleased audio streams:

player.on(AudioPlayerStatus.Idle, () => {
    // Clean up stream resources
    connection.destroy();
});

Lavalink for Scale

If your bot serves 50+ servers, Lavalink offloads audio processing:

  1. Run Lavalink server (Java) on the VPS
  2. Your bot sends commands to Lavalink
  3. Lavalink handles audio streaming
  4. Much lower bot RAM/CPU usage

This separates concerns: your bot handles Discord logic, Lavalink handles audio.

Space-Node Team

About the Author

Space-Node Team – Infrastructure Team – Experts in game server hosting, VPS infrastructure, and 24/7 streaming solutions with 15+ years combined experience.

Since 2023
500+ servers hosted
4.8/5 avg rating

Our team specializes in Minecraft, FiveM, Rust, and 24/7 streaming infrastructure, operating enterprise-grade AMD Ryzen 9 hardware in Netherlands datacenters. We maintain GDPR compliance and ISO 27001-aligned security standards.

View Space-Node's full team bio and credentials →

Launch Your VPS Today

Get started with professional VPS hosting powered by enterprise hardware. Instant deployment and 24/7 support included.

Hosting a Discord Music Bot on a VPS: Complete Setup Guide