Search code examples
javascriptnode.jsffmpegdiscord.jsaudio-player

Discord.js Music Bot ffmpeg not found?


I just started learning javascript with node.js and I am attempting to create a music bot, I've set up the command handler and everything, however, I keep getting this error when I try to run the play command

Error: FFmpeg/avconv not found! at Function.getInfo (C:\Users\johnd\OneDrive\Desktop\discordBot\node_modules\prism-media\src\core\FFmpeg.js:130:11) at Function.create (C:\Users\johnd\OneDrive\Desktop\discordBot\node_modules\prism-media\src\core\FFmpeg.js:143:38) at new FFmpeg (C:\Users\johnd\OneDrive\Desktop\discordBot\node_modules\prism-media\src\core\FFmpeg.js:44:27) at AudioPlayer.playUnknown (C:\Users\johnd\OneDrive\Desktop\discordBot\node_modules\discord.js\src\client\voice\player\BasePlayer.js:47:20) at VoiceConnection.play (C:\Users\johnd\OneDrive\Desktop\discordBot\node_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28) at C:\Users\johnd\OneDrive\Desktop\discordBot\commands\play.js:7:39 at processTicksAndRejections (internal/process/task_queues.js:97:5)

I'll post my play function below

async function playMusic(vc,songId) {
    const stream = await ytdl(songId,{type: 'opus',filter : 'audioonly'});
    vc.join().then(connection => {
        const dispatcher = connection.play(stream,{volume: 1});
        dispatcher.on('end', end => {
            console.log("Song ended!");
            vc.leave();
        }).catch(err => console.log(err));
    }).catch(err => console.log(err));
}

My proof of installation: https://i.sstatic.net/LRfJ4.jpg

Update 1: I'm still looking for others with this specific problem and can't find anything.


Solution

  • You need to run the following commands:

    1) npm install ffmpeg-static
    2) npm install @discordjs/opus
    3) npm install ytdl-core
    

    No need to install any binary or put it in the PATH, just install the above things like you installed discordjs. These things will show up in your package.json file after that. When you will host your bot in the cloud it will build it using the package.json.