server.queue.forEach(function(q) {
YTDL.getInfo(q, (error, info) => {
console.log(info["title"]);
message.reply('"' + info["title"] + '"');
});
});
for (var i = 0; i < server.queue.length; i++) {
YTDL.getInfo(server.queue[i], (error, info) => {
console.log(info["title"]);
message.reply('"' + info["title"] + '"');
});
}
I'm creating a music bot for a VoIP called Discord using Node.js and whenever either of the loops above execute, they print in a random order. How do I make it so that they are printed sequentially (server.queue[0], server.queue[1], server.queue[2]...)?
YTDL is a package called ytdl-core that downloads YouTube videos as well as display the info such as the title of a video using the video link. server.queue is an array of YouTube video links.