Reputation: 1
I'm trying to make a discord bot that plays an audio file. Right now, it joins the voice channel and plays the audio file, but refuses to leave afterwards. My code is below. Can anyone suggest some fixes so that my bot will leave the voice channel?
var voiceChannel = client.channels.cache.get("693280991812517952");
voiceChannel.join().then(connection =>{
const dispatcher = connection.play('./00.mp3');
dispatcher.on('end', () => voiceChannel.leave());
}).catch(err => console.log(err));
Upvotes: 0
Views: 1888
Reputation: 5174
You need to use the finish
event instead of the end
event.
So your solution is:
dispatcher.on('finish', () => voiceChannel.leave());
Upvotes: 1