I am encountering an error when my discord bot is trying to play an MP3 file in a Voice channel.
My code:
if(message.member.voiceChannel){
const connection = await message.member.voiceChannel.join();
const dispatcher = connection.playFile('./resources/shamebell.mp3');
dispatcher.on('finish', () => {
console.log('Finished playing!');
});
dispatcher.destroy(); // end the stream
}
The bot encounters an error when trying to play the MP3 file. It joins the Voice Channel that the user is in just fine. The bot should join the VC, play the MP3 file then leave afterwards.
Error in dispatcher:
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string
I have tried using both the absolute path as well as the relative path to the MP3. FFMPEG is installed and windows PATH set as well as NPM installed "ffmpeg-binaries": "^3.2.2-3".
Swapping from connection.playFile('./resources/shamebell.mp3');
to connection.play('./resources/shamebell.mp3');
Gives the error connection.play is not a function
at line 14:43
Any help on resolving this issue will be appreciated :)
New code with Discordv12 installed:
const connection = await message.member.voice.channel.join();
const dispatcher = connection.play('resources/shamebell.mp3');
dispatcher.on('finish', () => {
console.log('Finished playing!');
});
dispatcher.destroy();
Same issue:
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string
Path to MP3 file: C:\Users\Test\Desktop\bot\BotTest\resources\shamebell.mp3