Fixed autoplay with empty queue

This commit addresses the issue where autoplay was being activated even when the history queue had no tracks. The problem has been resolved to ensure smooth user experience
This commit is contained in:
Choco
2024-04-14 11:21:53 +08:00
parent 47389d6589
commit 9ffba9a801

View File

@@ -704,11 +704,14 @@ class Player(VoiceProtocol):
async def get_recommendations(self, *, track: Track = None) -> bool:
"""Get recommendations from Youtube or Spotify."""
if not track:
track = choice(self.queue.history(incTrack=True)[-5:])
try:
track = choice(self.queue.history(incTrack=True)[-5:])
except IndexError:
return False
if track.spotify:
spotify_tracks = await self._node._spotify_client.similar_track(seed_tracks=track.identifier)
tracks = [
Track(
track_id=None,