Repository: Cog-Creators/Red-DiscordBot

Issue:
[Audio] Logical errror
https://github.com/Cog-Creators/Red-DiscordBot/blob/098540b9e51157692c327fb8b3c3e01b9d87db20/redbot/cogs/audio/audio.py#L1658



Discussion:

Resolving patch:
diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py
--- a/redbot/cogs/audio/audio.py
+++ b/redbot/cogs/audio/audio.py
@@ -1638,6 +1638,7 @@ async def _get_spotify_tracks(self, ctx, query):
     async def _enqueue_tracks(self, ctx, query):
         player = lavalink.get_player(ctx.guild.id)
         guild_data = await self.config.guild(ctx.guild).all()
+        first_track_only = False
         if type(query) is not list:
             if not (
                 query.startswith("http")
@@ -1645,6 +1646,8 @@ async def _enqueue_tracks(self, ctx, query):
                 or query.startswith("ytsearch:")
             ):
                 query = f"ytsearch:{query}"
+            if query.startswith(("ytsearch", "localtracks")):
+                first_track_only = True
             tracks = await player.get_tracks(query)
             if not tracks:
                 return await self._embed_msg(ctx, _("Nothing found."))
@@ -1655,7 +1658,11 @@ async def _enqueue_tracks(self, ctx, query):
         queue_total_duration = lavalink.utils.format_time(queue_duration)
         before_queue_length = len(player.queue)
 
-        if ("ytsearch:" or "localtrack") not in query and len(tracks) > 1:
+        if not first_track_only and len(tracks) > 1:
+            # a list of Tracks where all should be enqueued
+            # this is a Spotify playlist aleady made into a list of Tracks or a
+            # url where Lavalink handles providing all Track objects to use, like a
+            # YouTube or Soundcloud playlist
             track_len = 0
             for track in tracks:
                 if guild_data["maxlength"] > 0:
@@ -1688,6 +1695,9 @@ async def _enqueue_tracks(self, ctx, query):
             if not player.current:
                 await player.play()
         else:
+            # a ytsearch: prefixed item where we only need the first Track returned
+            # this is in the case of [p]play <query>, a single Spotify url/code
+            # or this is a localtrack item
             try:
                 single_track = tracks[0]
                 if guild_data["maxlength"] > 0:
@@ -3077,14 +3087,17 @@ async def _search_button_action(self, ctx, tracks, emoji, page):
 
         except AttributeError:
             if command == "search":
+                # [p]local search
                 return await ctx.invoke(self.play, query=("localtracks/{}".format(search_choice)))
             search_choice = search_choice.replace("localtrack:", "")
             local_path = await self.config.localpath()
             if not search_choice.startswith(local_path):
+                # folder display for [p]local play
                 return await ctx.invoke(
                     self.search, query=("localfolder:{}".format(search_choice))
                 )
             else:
+                # file display for a chosen folder in the [p]local play menus
                 return await ctx.invoke(self.play, query=("localtrack:{}".format(search_choice)))
 
         embed = discord.Embed(


Test patch: