Androz2091 / discord-music-bot

The perfect music bot for your Discord server! 🤘
238 stars 128 forks source link

Error not supporting spotify urls #85

Open shirokid opened 2 years ago

shirokid commented 2 years ago

When I try to put the spotify urls, the module "play-dl" emits an error Streaming from Spotify is not supported. Please use search() to find a similar track on YouTube or SoundCloud instead. I used play-dl in the onBeforeCreateStream function while creating the queue, from when it caused this error whenever I try to play with spotify urls. Any help would be appreciated. the code :

async onBeforeCreateStream(track, source) {
  if (track.url.includes('spotify.com')) source = 'spotify';
  if (source == 'youtube') return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream;
  else if (source == "spotify") {
    let search = await playdl.search(`${track.title} by ${track.author}`, { source: { youtube: 'video' } }).then(x => x[0].url);
    return (await playdl.stream(search, { discordPlayerCompatibility: true })).stream;
  }
  console.log(track, source);
}