hmes98318 / Music-Disc

A Discord music bot, supports YouTube, Spotify, SoundCloud, Deezer streams and web dashboard.
https://musicdisc.ggwp.tw
MIT License
115 stars 106 forks source link

Unable to play Spotify playlists #11

Closed HTF8 closed 1 year ago

HTF8 commented 1 year ago

Describe the bug The bot crashes when trying to play a Spotify playlist, producing the below error. Single Spotify songs work fine.

D:\Programs\Discord Bot\node_modules\discord-player\dist\Player.js:432
                    playlist.tracks = spotifyPlaylist.tracks.items.map((m) => {
                                                             ^

TypeError: Cannot read properties of undefined (reading 'items')
    at Player.search (D:\Programs\Discord Bot\node_modules\discord-player\dist\Player.js:432:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.execute (D:\Programs\Discord Bot\src\commands\play.js:14:21)

To Reproduce Steps to reproduce the behavior:

  1. Try to play a Spotify playlist (ex: +play https://open.spotify.com/album/0jo2HJc2mEB0WEiy1MS3Ju?si=h3l7FG_MQ3Wx-1dr8uQfMw)
  2. If a song is already playing, it will stop
  3. The bot will crash, citing error TypeError: Cannot read properties of undefined (reading 'items')

Expected behavior The bot should play the Spotify playlist.

Screenshots Successfully playing a single track from Spotify: image Failing to play a playlist: image YouTube playlists are still fine: image

Version Information:

Additional context Bot has also recently been crashing occasionally while idle, citing the following error:

D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:90
      throw new Error(`Found unknown component type: ${data.type}`);
      ^

Error: Found unknown component type: 5
    at createComponent (D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:90:13)
    at D:\Programs\Discord Bot\node_modules\discord.js\src\structures\ActionRow.js:21:43
    at Array.map (<anonymous>)
    at new ActionRow (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\ActionRow.js:21:34)
    at createComponent (D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:82:14)
    at D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:156:50
    at Array.map (<anonymous>)
    at Message._patch (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:156:41)
    at new Message (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:50:10)
    at MessageManager._add (D:\Programs\Discord Bot\node_modules\discord.js\src\managers\CachedManager.js:44:32)
hmes98318 commented 1 year ago

Describe the bug The bot crashes when trying to play a Spotify playlist, producing the below error. Single Spotify songs work fine.

D:\Programs\Discord Bot\node_modules\discord-player\dist\Player.js:432
                    playlist.tracks = spotifyPlaylist.tracks.items.map((m) => {
                                                             ^

TypeError: Cannot read properties of undefined (reading 'items')
    at Player.search (D:\Programs\Discord Bot\node_modules\discord-player\dist\Player.js:432:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.execute (D:\Programs\Discord Bot\src\commands\play.js:14:21)

This is doscord-player module errors,
This can temporarily fix the problem until doscord-player is sloved this errors. First run npm update, then try to edit the following path file node_modules\discord-player\dist\Player.js:430

// line 430
else {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const { parse, formatOpenURL } = require('spotify-uri');
    playlist.tracks = spotifyPlaylist.trackList.map((m) => {
        const data = new Track_1.default(this, {
            title: m.title ?? "",
            description: m.title ?? "",
            author: m.subtitle ?? "Unknown Artist",
            url: formatOpenURL(parse(m.uri)) ?? query,
            thumbnail: "https://www.scdn.co/i/_global/twitter_card-default.jpg",
            duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.duration)),
            views: 0,
            requestedBy: options.requestedBy,
            playlist,
            source: "spotify"
        });
        return data;
    });
}

It works fine but doesn't show thumbnails.

img
hmes98318 commented 1 year ago

Additional context Bot has also recently been crashing occasionally while idle, citing the following error:

D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:90
      throw new Error(`Found unknown component type: ${data.type}`);
      ^

Error: Found unknown component type: 5
    at createComponent (D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:90:13)
    at D:\Programs\Discord Bot\node_modules\discord.js\src\structures\ActionRow.js:21:43
    at Array.map (<anonymous>)
    at new ActionRow (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\ActionRow.js:21:34)
    at createComponent (D:\Programs\Discord Bot\node_modules\discord.js\src\util\Components.js:82:14)
    at D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:156:50
    at Array.map (<anonymous>)
    at Message._patch (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:156:41)
    at new Message (D:\Programs\Discord Bot\node_modules\discord.js\src\structures\Message.js:50:10)
    at MessageManager._add (D:\Programs\Discord Bot\node_modules\discord.js\src\managers\CachedManager.js:44:32)

Try update Bot to v1.2.5. this version fixed button crash issue.

HTF8 commented 1 year ago

That fixed it. Thank you for your quick assistance.

Haven't had any crashes since updating to 1.2.5.

👍