add songs from array to queue one by one

Viewed 33

So I am new to javascript and am wondering how I can extract every song in a spotify playlist, then put them into the queue.

Currently I have this code:

// Search for the playlist using the discord-player
            let url = interaction.options.getString("url") // The url of the spotify playlist

            const tracks = getTracks(url); //returns an array containing the first 100 songs in a playlist
            console.log(tracks);

            async function getResults(track){
                const result = await client.player.search(track, {
                    requestedBy: interaction.user,
                    searchEngine: QueryType.AUTO
                })
                if (result.tracks.length === 0)
                    return interaction.reply(`No playlists found with ${url}`)

                await queue.addTracks(result.track) //Adds the track to the queue
            }

            tracks.forEach(getResults(tracks)); // (should) run the function for every single song

This code doesn't work though and I wonder how do I do this?

0 Answers
Related