I'm building a discord bot and when I try to make it play music in the voice channel, it just doesn't work. Is the dispatcher const and/or connection.play() part of some library? I'm currently using discord.js v12 and following their guide available here: https://v12.discordjs.guide/voice/
Note = I have @discordjs/opus installed, as well as FFmpeg, however, I don't require FFmpeg in my code and I don't know if I should. For that matter, I also don't see where I should use the opus library in my code.
The part that I get an error from my code is as follows:
pathMusic = musicTitle + '.mp3';
const dispatcher = connection.play(pathMusic);
dispatcher.on('start', () => {
console.log(musicurl + ' is now playing!');
msg.channel.send('Now playing: ' + musicTitle);
});
dispatcher.on('finish', () => {
console.log(musicTitle + ' has finished playing!');
});
dispatcher.on('error', console.error);
msg.channel.send('Now playing: ' + musicTitle);
Any help would be deeply appreciated!
Assuming you want to play music from youtube, you're missing 2 dependencies:
And for the discord/opus, I had an error when I tried to host it on Heroku, I think it's because the server is Linux based and it was needed for buffering(someone corrects me if I'm wrong)