So I'm making progress on my music bot. Currently, it shuffles the playlist, and plays every song in the playlist once. The next step is for me to make him re-shuffle the playlist after it has played every song, and go again (I'll make the catch to 'stop' him using a command later). In theory - all I have to do is add in a check that 'if the array contains an entry in the 0 position, play that next song', otherwise 'if the array was empty, shuffle the playlist again, and THEN play the next song'
Unfortunately, even if the next song is undefined - the check is failing, and after the first run-through of the playlist, he starts spamming songs that are undefined. I have tried multiple ways of checking this. Checking if the entry in the array is undefined, checking if the length of the array is undefined, checking whether the entry was or was not contained in the original list of songs - same problem for all of them.
function PlaySong(connection, channel, SongToPlay) {
console.log('Now playing '+SongToPlay[0]+'.'); //announce the song
message.channel.send('Now playing '+SongToPlay[0]+'.');
const dispatcher = connection.play('./Scythe Digital Edition - Soundtrack/'+SongToPlay[0]+'.mp3'); //play the song
dispatcher.setVolume(0.1); //at this volume
dispatcher.on("finish", () => { //when the song concludes
SongToPlay.shift(); //remove that song from the list of songs to play
if (!isNullOrUndefined(SongToPlay[0]) || SongToPlay[0] !== '') { //if the list of songs is not empty
PlaySong(connection, channel, SongToPlay); //repeat the above for the next song
}
else { //otherwise if it was empty
SongToPlay = shuffle(testbells); //shuffle the playlist and repopulate the list of songs to play
PlaySong(connection, channel, SongToPlay); //then repeat the above for the next song
//channel.leave();
//return;
}
});
}