I am trying to grab all the songs from a spotify playlist, then add the songs to a queue. But instead it is giving me that error. This is my current code that I am using:
else if (interaction.options.getSubcommand() === "splaylist") {
// Search for the playlist using the discord-player
let url = interaction.options.getString("url")
const tracks = await getTracks(url).then(tracks => {return tracks}); //returns an array containing the first 100 songs in a playlist
console.log(tracks); //tracks is the information of all of the tracks
async function getResults(track){ // a function that is supposed to add every song in the tracks const to the queue by getting the name and artist and searching that
const result = await client.player.search(track, {
requestedBy: interaction.user,
searchEngine: QueryType.AUTO
})
if (result.tracks.length === 0)
return await interaction.reply(`No playlists found with ${url}`)
await queue.addTrack(result.track) //Adds the track to the queue
}
// (should) run the function for every single song
await tracks.forEach(track => getResults(track.toString()));
}
Full error message:
InvalidTrack: [InvalidTrack] invalid track
at new PlayerError (E:\DiscordMusicBot\node_modules\discord-player\dist\Structures\PlayerError.js:28:15)
at Queue.addTrack (E:\DiscordMusicBot\node_modules\discord-player\dist\Structures\Queue.js:235:19)
at getResults (E:\DiscordMusicBot\commands\play.js:113:29)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
createdAt: 2022-09-23T14:48:21.556Z,
statusCode: 'InvalidTrack'
}