Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
603 stars 190 forks source link

Playing albums/playlists from all major streaming platforms does not work #1643

Closed yazninja closed 1 year ago

yazninja commented 1 year ago

Describe the bug Discord-player will happily play tracks/ singles, bhowever when there are multiple tracks being returned as a searchResult, it errors out.

To Reproduce Steps to reproduce the behavior: play any of these links;

  1. https://open.spotify.com/album/1ONjVRtxAqiTivu0EiEBm5?si=7Wp_NnggT7i-AcWvy-RbGg
  2. https://music.apple.com/ph/playlist/2000s-alternative-essentials/pl.7f3a307b0f2e49b1b521b4d4d5c21c7c
  3. https://www.youtube.com/watch?v=572QgKc6xT8&list=RDCLAK5uy_k27uu-EtQ_b5U2r26DNDZOmNqGdccUIGQ

Expected behavior to play the playlist and add it to queue if there are multiple tracks

Screenshots image image

Please complete the following information:

ddemile commented 1 year ago

Hey, something like that should work :

let query = interaction.options.getString("search_terms")

const queue = client.player.nodes.create(interaction.guild, {
    metadata: {
        channel: interaction.channel,
        client: interaction.guild.members.me,
        requestedBy: interaction.user,
    },
    selfDeaf: true,
    volume: 80,
    leaveOnEmpty: true,
    leaveOnEmptyCooldown: 300000,
    leaveOnEnd: true,
    leaveOnEndCooldown: 300000,
});
if (!queue.connection) await queue.connect(interaction.member.voice?.channelId)
const search = await client.player.search(query, { searchEngine: QueryType.AUTO })
queue.addTrack(search.tracks)
await queue.node.play()
febkosq8 commented 1 year ago

Try the following as it is working for me (YT and Spotify playlists):

Deleting node_modules and package-lock files. Then run npm i and try again

sulsalloom commented 1 year ago

experiencing the same issue right now tried deleting node modules and package-lock files still not working

febkosq8 commented 1 year ago

Can you guys share your play code so that we can take a look ?

sulsalloom commented 1 year ago

Can you guys share your play code so that we can take a look ?

async function play_handler(interaction) {
  const channel = interaction.member.voice.channel;
  if (!channel)
    return interaction.reply("You are not connected to a voice channel!"); 
  const query = interaction.options.getString("query", true); 

  await interaction.deferReply();

  try {
    const searchResult = await player.search(query).catch(() => {
      console.log("search failed");
    });

    if (!searchResult.hasTracks())
      return interaction.followUp({content: "No results were found!"});
    const {track} = await player.play(channel, searchResult, {
      nodeOptions: {
        metadata: interaction,
        selfDeaf: false,
        leaveOnEmpty: true,
        leaveOnEmptyCooldown: 300000,
        leaveOnEnd: true,
        leaveOnEndCooldown: 300000,
      },
    });

    return interaction.followUp(`**${track.title}** enqueued!`);
  } catch (e) {
    return interaction.followUp(`Something went wrong: ${e}`);
  }
}

Node Version: 18.14.0 Discord Player Version: 6.0.0 Discord.js Version: 14.7.1

febkosq8 commented 1 year ago

@sulsalloom I tried your code. Only thing I had to change was one line , metadata: interaction to metadata: interaction.channel.

After that everything worked as expected. Can you try that change to see if it fixes it. image

febkosq8 commented 1 year ago

@yazninja

The yt link that you gave (https://www.youtube.com/watch?v=572QgKc6xT8&list=RDCLAK5uy_k27uu-EtQ_b5U2r26DNDZOmNqGdccUIGQ) isn't a playlist, it's probably a yt music mix or something similar. (IDK much about those)

Playlist will have youtube.com/playlist? in it. Player as far as I tested only supports such links.

The other two links worked perfectly fine for me.

sawdex commented 1 year ago

image

febkosq8 commented 1 year ago

image

The new event for same is playerStart not trackStart

sulsalloom commented 1 year ago

@sulsalloom I tried your code. Only thing I had to change was one line , metadata: interaction to metadata: interaction.channel.

After that everything worked as expected. Can you try that change to see if it fixes it. image

still the same using this playlist https://www.youtube.com/playlist?list=PLOHoVaTp8R7dfrJW5pumS0iD_dhlXKv17 also tested @yazninja other 2 lists both of them don't work

sawdex commented 1 year ago

i tried trackStart and still @febkosq8

febkosq8 commented 1 year ago

still the same using this playlist https://www.youtube.com/playlist?list=PLOHoVaTp8R7dfrJW5pumS0iD_dhlXKv17 also tested @yazninja other 2 lists both of them don't work

Just now tried that link works for me. Do you have your bot code on git ?

febkosq8 commented 1 year ago

i tried trackStart and still @febkosq8

Do you have your bot code on git ?

febkosq8 commented 1 year ago

@sawdex

Please create a git repo to show your code next time.

Can you update your event code to this and try again to see if its broadcasting the event ?

player.events.on('playerStart', (queue, track) => {
console.log("PlayerStart HIT");
if (queue.repeatMode !== 0) return;
queue.metadata.channel?.send({ embeds: [embed.Embed_play("Playing", track.title, track.url, track.duration, track.thumbnail, settings(queue))] });
});
sawdex commented 1 year ago

@febkosq8 image no embed i think the error from play command

febkosq8 commented 1 year ago

image no embed i think the error from play command

So the event is working as intended. If you are fine with a simple update to the user, try what I have.

queue.metadata.send(`â–¶ | Started playing: **${track.title}**`);
sawdex commented 1 year ago

@febkosq8 now working thank you, now I know that the problem is from embed.

febkosq8 commented 1 year ago

@sulsalloom

You only have discord-player@6.0.0 in your package. You will need @discord-player/extractor, @discord-player/equalizer & @discord-player/utils for everything to properly work.

Run the following in terminal

npm i discord-player@latest @discord-player/extractor@latest @discord-player/equalizer@latest @discord-player/utils@latest

Then delete node_modules & package-lock.json. Then run the following and try again

npm cache clean --force
npm i
sulsalloom commented 1 year ago

@sulsalloom

You only have discord-player@6.0.0 in your package. You will need @discord-player/extractor, @discord-player/equalizer & @discord-player/utils for everything to properly work.

Run the following in terminal

npm i discord-player@latest @discord-player/extractor@latest @discord-player/equalizer@latest @discord-player/utils@latest

Then delete node_modules & package-lock.json. Then run the following and try again

npm cache clean --force
npm i

still same issue i pushed to the rep if you wanna have a look

twlite commented 1 year ago

@yazninja

The yt link that you gave (https://www.youtube.com/watch?v=572QgKc6xT8&list=RDCLAK5uy_k27uu-EtQ_b5U2r26DNDZOmNqGdccUIGQ) isn't a playlist, it's probably a yt music mix or something similar. (IDK much about those)

Playlist will have youtube.com/playlist? in it. Player as far as I tested only supports such links.

The other two links worked perfectly fine for me.

Mixes are not supported, see skdhg/youtube-sr#31

febkosq8 commented 1 year ago

@sulsalloom

I tried your code on my local machine, and it didn't work for me. I tried changing stuff but nothing worked out. Any single tracks would work. But no playlist would work. From debug logs, I found out that the searchResults are being fetched as expected but player.play doesn't seem to work. I also checked player debug event and every standard extractors were being loaded as expected.

Don't know what is going wrong over here. My best guess is the way your bot is structured. My bot uses cjs while yours use esm. I will try to dig around more in free time.

Error Stack

Error: Play request received but track was not provided
    at GuildQueuePlayerNode.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:863:13)
    at GuildQueuePlayerNode.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:888:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _Player.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:2581:7)
    at async play_handler (<dir>/discord-bot/commands/play.js:28:5)
sulsalloom commented 1 year ago

@sulsalloom

I tried your code on my local machine, and it didn't work for me. I tried changing stuff but nothing worked out. Any single tracks would work. But no playlist would work. From debug logs, I found out that the searchResults are being fetched as expected but player.play doesn't seem to work. I also checked player debug event and every standard extractors were being loaded as expected.

Don't know what is going wrong over here. My best guess is the way your bot is structured. My bot uses cjs while yours use esm. I will try to dig around more in free time.

Error Stack

Error: Play request received but track was not provided
    at GuildQueuePlayerNode.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:863:13)
    at GuildQueuePlayerNode.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:888:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _Player.play (<dir>/discord-bot/node_modules/discord-player/dist/index.mjs:2581:7)
    at async play_handler (<dir>/discord-bot/commands/play.js:28:5)

changed my code to cjs and now it works thats weird

febkosq8 commented 1 year ago

changed my code to cjs and now it works thats weird

Yea, that should not be a thing.