Discord music bot shows FFmpeg error and won't stream audio

I’m having trouble with my Discord bot that’s supposed to stream music. It’s built using discord.js and youtube-dl-core but when I try to run it, I get an FFmpeg error. Here’s my current setup:

const discord = require('discord.js');
const client = new discord.Client();
const youtubeDL = require('ytdl-core');

const BOT_TOKEN = 'YOUR_TOKEN_HERE';
const COMMAND_PREFIX = '!';
const botVersion = '2.0';
const guildData = {};

client.on('ready', () => {
    console.log('Music bot is running! Version: ' + botVersion);
});

client.on('message', msg => {
    let commands = msg.content.substring(COMMAND_PREFIX.length).split(' ');
    
    switch(commands[0]) {
        case 'start':
            
            function startPlayback(voiceConnection, msg) {
                var guildInfo = guildData[msg.guild.id];
                
                guildInfo.audioStream = voiceConnection.play(youtubeDL(guildInfo.playlist[0], {filter: 'audioonly'}));
                
                guildInfo.playlist.shift();
                
                guildInfo.audioStream.on('finish', function() {
                    if(guildInfo.playlist[0]) {
                        startPlayback(voiceConnection, msg);
                    } else {
                        voiceConnection.disconnect();
                    }
                });
            }
            
            if(!commands[1]) {
                msg.channel.send('Please provide a YouTube URL!');
                return;
            }
            
            if(!msg.member.voice.channel) {
                msg.channel.send('Join a voice channel first!');
                return;
            }
            
            if(!guildData[msg.guild.id]) guildData[msg.guild.id] = {
                playlist: []
            };
            
            var guildInfo = guildData[msg.guild.id];
            guildInfo.playlist.push(commands[1]);
            
            if(!msg.guild.voice) {
                msg.member.voice.channel.join().then(function(voiceConnection) {
                    startPlayback(voiceConnection, msg);
                });
            }
            
        break;
    }
});

client.login(BOT_TOKEN);

The error message I keep getting is:

FFmpeg/avconv not found! Error at Function.getInfo
UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found!

I think FFmpeg might not be installed properly on my system but I’m not sure how to fix this. Has anyone dealt with this issue before?

yea so u gotta get ffmpeg installed manually. for windows, grab it from the official site n make sure it’s in ur PATH. if ur on linux, just do sudo apt install ffmpeg. restart ur terminal after and it should work!

That FFmpeg error is definitely what’s breaking your audio streaming. But installing FFmpeg alone won’t fix it - you should switch to @discordjs/voice and @discordjs/opus since your voice connection code looks outdated for newer discord.js versions. Make sure you’ve got the audio dependencies too: npm install node-opus or npm install opusscript. I had the same problem and even with FFmpeg installed, missing opus encoders still broke streaming. Run your bot with --trace-warnings to see exactly what’s failing in the audio pipeline.

Had the exact same issue when setting up my first music bot. FFmpeg installation is your problem. I downloaded the static build from Download FFmpeg and extracted it to C:\ffmpeg on Windows. Add the bin folder to your system PATH. Open a new command prompt and run ffmpeg -version to check it’s working. Some hosting services like Heroku need FFmpeg as a buildpack instead of manual installation. Restart your IDE and terminal completely after installing - they cache PATH variables.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.