I would like the bot to join a voice channel when someone joins and then play a sound file.
So far, I've gotten the bot to join the voice channel but it just doesn't play the sound and no errors show so I don't really know what is going wrong.
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login('BOT TOKEN');
bot.on('voiceStateUpdate', (oldMember, newMember) => {
let newUserChannel = newMember.voiceChannel
let oldUserChannel = oldMember.voiceChannel
let textChannel = oldMember.guild.channels.get('TEXTCHANNEL ID')
if(oldUserChannel === undefined && newUserChannel !== undefined) {
if (newMember.id === 'MEMEBER ID') //Member 1
{
newUserChannel.join()
.then(connection => {
console.log("Joined voice channel!");
const dispatcher = connection.playFile("C:\Users\NAME\Documents\Welcome_Bot\music\bossman.mp3");
dispatcher.on("end", end => {newUserChannel.leave()});
})
.catch(console.error);
}
else if (newMember.id === 'MEMEBER ID') //Member 2
{
textChannel.send('Hello Member 2')
}
else if (newMember.id === 'MEMEBER ID') //Member 3
{
textChannel.send('Hello Member 3')
}
else //Random
{
textChannel.send("Hello")
}
}
});
Groovy is one of the most popular Discord music bots. There are a variety of Groovy bot commands that you can use. With the Groovy music bot, you can play songs through website links or file uploads or search for specific songs. You can also create a song queue.
I believe your issue is that the bot isn't actually joining the channel before you call the dispatcher. The bot needs to be told to enter the channel before you call the dispatcher. Havn't worked on audio in a while but I believe that connection.join()
right above your dispatcher would work. You may need to .then()
to ensure it dosn't initilize the dispatcher before the bot joins the channel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With