let playlistList = db.get("server").find({"id": msg.guild.id}).get("playlists").value();
let PlaylistsEmbed = new Discord.MessageEmbed()
playlistList.forEach(playlist =>{
Youtube.getPlaylist(playlist.url).then(result => {
PlaylistsEmbed.addField(`"**${playlist.name}**"`, result.title);
}).catch(()=>{
Youtube.getVideo(playlist.url).then(video => {
PlaylistsEmbed.addField(`"**${playlist.name}**"`, video.title);
}).catch(()=>{
msg.channel.send("Invalid URL!");
})
})
});
msg.channel.send({embed: PlaylistsEmbed});
}
How can I execute the promise before calling msg.channel.send({embed: PlaylistsEmbed});
?
PlaylistsEmbed.addField(`"**${playlist.name}**"`, result.title);
doesn't seem to work if it's called inside the promise.
I tried putting a new Promise() around it, but I cannot make it work because of the forEach, if I resolve it inside of the forEach, it only adds one entry.