Voice Channel Audio: Building a Music Bot That Actually Works

Published on

How to build a Discord music bot with voice channel support. Covers audio streaming, queue management, and why self-hosted music bots are better than public ones.

Written by Jochem, Infrastructure Expert, 5-10 years experience in game server hosting, VPS infrastructure, and 24/7 streaming solutions. Read author bio →

After major music bots (Rythm, Groovy) were shut down by Google, self-hosted music bots became the standard. Here's how to build one that works reliably.

Discord music bot in voice channel

Why Self-Hosted

FactorPublic BotSelf-Hosted
ReliabilityShared load, outagesYour server, your uptime
Audio qualityOften compressedFull quality
FeaturesLimitedWhatever you build
PrivacyYour data on their serverYour data stays with you
CostFree (with limitations)Hosting cost

Technical Setup

Dependencies

For Node.js (discord.js):

npm install discord.js @discordjs/voice @discordjs/opus sodium-native play-dl

For Python (discord.py):

pip install discord.py[voice] yt-dlp

Both require FFmpeg installed on the system:

apt install ffmpeg

Basic Music Bot (Node.js)

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

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

const queue = new Map();

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!play')) {
        const query = message.content.slice(6);
        const voiceChannel = message.member.voice.channel;
        
        if (!voiceChannel) {
            return message.reply('Join a voice channel first!');
        }
        
        const connection = joinVoiceChannel({
            channelId: voiceChannel.id,
            guildId: message.guild.id,
            adapterCreator: message.guild.voiceAdapterCreator
        });
        
        const stream = await play.stream(query);
        const resource = createAudioResource(stream.stream, {
            inputType: stream.type
        });
        
        const player = createAudioPlayer();
        player.play(resource);
        connection.subscribe(player);
        
        message.reply(`Now playing: ${query}`);
    }
});

Queue System

A proper music bot needs a queue:

class MusicQueue {
    constructor() {
        this.songs = [];
        this.playing = false;
    }
    
    add(song) {
        this.songs.push(song);
    }
    
    next() {
        return this.songs.shift();
    }
    
    clear() {
        this.songs = [];
    }
    
    get length() {
        return this.songs.length;
    }
}

Essential Commands

CommandAction
!play [query]Search and play a song
!skipSkip current track
!queueShow upcoming songs
!pausePause playback
!resumeResume playback
!volume [1-100]Adjust volume
!leaveDisconnect from voice

Audio Quality

Bitrate Settings

Discord voice channels support different bitrates:

Channel QualityBitrateServer Boost Level
Standard64 kbpsNone
Improved128 kbpsLevel 1
High256 kbpsLevel 2
Best384 kbpsLevel 3

Your bot should encode audio at the channel's maximum supported bitrate for best quality.

Audio Processing

Add equalizer and volume normalization:

# FFmpeg filter for loudness normalization
-af "loudnorm=I=-14:TP=-1:LRA=11,equalizer=f=100:width_type=h:width=200:g=3"

This normalizes volume between tracks (no jarring volume changes) and adds a subtle bass boost.

Hosting Requirements

FeatureCPURAM
1 voice connection0.2 cores100MB
5 voice connections1 core300MB
10 voice connections2 cores500MB

Music bots are surprisingly lightweight. The FFmpeg encoding uses some CPU, but a single voice connection barely registers on modern hardware.

Space-Node's Discord bot hosting handles music bot workloads easily, even on the free Small plan for single-server bots. For bots serving multiple servers simultaneously, the Middle or Large plan provides the resources for concurrent voice connections.

Self-hosted music bots give you control over your audio experience. No arbitrary shutdowns, no quality limitations, and no dependence on a service that might disappear tomorrow.

Jochem

About the Author

Jochem, Infrastructure Expert, expert in game server hosting, VPS infrastructure, and 24/7 streaming solutions with 5-10 years experience.

Since 2023
500+ servers hosted
4.8/5 avg rating

I specialize in Minecraft, FiveM, Rust, and 24/7 streaming infrastructure, operating enterprise-grade AMD Ryzen 9 hardware in Netherlands datacenters.

View my full bio and credentials →

Keep Your Bot Online 24/7

Reliable Discord bot hosting powered by enterprise AMD Ryzen 9 hardware. Start free, upgrade anytime with guaranteed uptime.