I have a discord music bot. My problem is wrong sequence in printing titles of youTube videos. When I'm going to send results into the text channel I see a random sending titles, not that what I expected.
I've tried to use async/await functions, but it still doesn't work.
function queueNow(message) {
let arr = queueArr; //array with urls
if(arr !== undefined && arr.length !== 0) {
let mes = "```Elm";
let counterPlaylist = 0;
if(arr.length != 0) {
let flag = true;
arr.forEach(composition => {
ytdl.getInfo(composition, function(err, info) {
if(err === null) {
if(info === undefined) {
flag = false;
}
if(flag) {
counterPlaylist++;
mes += "\n" + counterPlaylist + ") " + info.title;
}
if(counterPlaylist === arr.length) {
mes += "\n```"
message.channel.send(mes);
}
}
});
})
}
}
}