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?