So im making a discord bot using nodejs with discord.js(https://discord.js.org/#/docs). I cannot get my bot to play a stream the second time i call it. The first time it plays and then triggers the end event. It then splices it out of the list and moves onto the next xong in the queue. But it never plays sound the second time, but it does play it as the end event does call apropriately when it should end otherwise.
function End(){
console.log("Ended")
playing = false;
playlist = playlist.splice(1);
Play();
}
function Play(){
if(!playing && playlist.length > 0){
var voiceConnection = guild.voiceConnection;
if(voiceConnection){
const stream = ytdl(playlist[0].url, { filter : 'audioonly' });
const broadcast = client.createVoiceBroadcast().playStream(stream);;
playing = true;
const dispatcher = voiceConnection.playBroadcast(broadcast);
broadcast.on('end', (reason) => {
console.log('reason: '+ reason);
End();
});
chatchannel.send("Playing " + playlist[0].name + " | " + playlist[0].author);
console.log("Playing " + playlist[0].name + " | " + playlist[0].author + " Length: " + playlist[0].length);
}else{
channel.join().then(Play);
}
}
}
This is the code i have at the moment, although i have tried lots of different methods of playing a stream.
via Hayhay G
No comments:
Post a Comment