# Buggy code
async def _playlist_upload(
    self, ctx: commands.Context, *, scope_data: ScopeParser = None
):
    """Uploads a playlist file as a playlist for the bot.

    V2 and old V3 playlist will be slow.
    V3 Playlist made with [p]playlist download will load a lot faster.

    **Usage**:
    ​ ​ ​ ​ [p]playlist upload args

    **Args**:
    ​ ​ ​ ​ The following are all optional:
    ​ ​ ​ ​ ​ ​ ​ ​ --scope <scope>
    ​ ​ ​ ​ ​ ​ ​ ​ --author [user]
    ​ ​ ​ ​ ​ ​ ​ ​ --guild [guild] **Only the bot owner can use this**

    Scope is one of the following:
    ​ ​ ​ ​ Global
    ​ ​ ​ ​ Guild
    ​ ​ ​ ​ User

    Author can be one of the following:
    ​ ​ ​ ​ User ID
    ​ ​ ​ ​ User Mention
    ​ ​ ​ ​ User Name#123

    Guild can be one of the following:
    ​ ​ ​ ​ Guild ID
    ​ ​ ​ ​ Exact guild name

    Example use:
    ​ ​ ​ ​ [p]playlist upload
    ​ ​ ​ ​ [p]playlist upload --scope Global
    ​ ​ ​ ​ [p]playlist upload --scope User
    """
    if scope_data is None:
        scope_data = [PlaylistScope.GUILD.value, ctx.author, ctx.guild, False]
    scope, author, guild, specified_user = scope_data
    temp_playlist = FakePlaylist(author.id, scope)
    if not await self.can_manage_playlist(scope, temp_playlist, ctx, author, guild):
        return

    if not await self._playlist_check(ctx):
        return
    player = lavalink.get_player(ctx.guild.id)

    await self._embed_msg(
        ctx,
        _(
            "Please upload the playlist file. Any other message will cancel this operation."
        ),
    )

    try:
        file_message = await ctx.bot.wait_for(
            "message", timeout=30.0, check=MessagePredicate.same_context(ctx)
        )
    except asyncio.TimeoutError:
        return await self._embed_msg(ctx, _("No file detected, try again later."))
    try:
        file_url = file_message.attachments[0].url
    except IndexError:
        return await self._embed_msg(ctx, _("Upload cancelled."))
    file_suffix = file_url.rsplit(".", 1)[1]
    if file_suffix != "txt":
        return await self._embed_msg(ctx, _("Only playlist files can be uploaded."))
    try:
        async with self.session.request("GET", file_url) as r:
            uploaded_playlist = await r.json(content_type="text/plain")
    except UnicodeDecodeError:
        return await self._embed_msg(ctx, _("Not a valid playlist file."))

    new_schema = uploaded_playlist.get("schema", 1) >= 2
    version = uploaded_playlist.get("version", "v2")

    if new_schema and version == "v3":
        uploaded_playlist_url = uploaded_playlist.get("playlist_url", None)
        track_list = uploaded_playlist.get("tracks", [])
    else:
        uploaded_playlist_url = uploaded_playlist.get("link", None)
        track_list = uploaded_playlist.get("playlist", [])

    uploaded_playlist_name = uploaded_playlist.get(
        "name", (file_url.split("/")[6]).split(".")[0]
    )
    if (
        not uploaded_playlist_url
        or not match_yt_playlist(uploaded_playlist_url)
        or not (
            await self.music_cache.lavalink_query(
                ctx,
                player,
                audio_dataclasses.Query.process_input(uploaded_playlist_url),
            )
        )[0].tracks
    ):
        if version == "v3":
            return await self._load_v3_playlist(
                ctx,
                scope,
                uploaded_playlist_name,
                uploaded_playlist_url,
                track_list,
                author,
                guild,
            )
        return await self._load_v2_playlist(
            ctx,
            track_list,
            player,
            uploaded_playlist_url,
            uploaded_playlist_name,
            scope,
            author,
            guild,
        )
    return await ctx.invoke(
        self._playlist_save,
        playlist_name=uploaded_playlist_name,
        playlist_url=uploaded_playlist_url,
        scope_data=(scope, author, guild, specified_user),
    )


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
ret = await coro(*args, **kwargs)
File "/home/martinebots/martinebotscogs/cogs_modified/audio/audio.py", line 3183, in play
await self._enqueue_tracks(ctx, query)
File "/home/martinebots/martinebotscogs/cogs_modified/audio/audio.py", line 3885, in _enqueue_tracks
result, called_api = await self.music_cache.lavalink_query(ctx, player, query)
File "/home/martinebots/martinebotscogs/cogs_modified/audio/apis.py", line 911, in lavalink_query
results = await player.load_tracks(query)
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/lavalink/rest_api.py", line 300, in load_tracks
self.__check_node_ready()
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/lavalink/rest_api.py", line 268, in __check_node_ready
raise RuntimeError("Cannot execute REST request when node not ready.")
RuntimeError: Cannot execute REST request when node not ready.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/martinebots/martinebotsvenv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: Cannot execute REST request when node not ready.```

# Fixed code
async def _playlist_upload(
    self, ctx: commands.Context, *, scope_data: ScopeParser = None
):
    """Uploads a playlist file as a playlist for the bot.

    V2 and old V3 playlist will be slow.
    V3 Playlist made with [p]playlist download will load a lot faster.

    **Usage**:
    ​ ​ ​ ​ [p]playlist upload args

    **Args**:
    ​ ​ ​ ​ The following are all optional:
    ​ ​ ​ ​ ​ ​ ​ ​ --scope <scope>
    ​ ​ ​ ​ ​ ​ ​ ​ --author [user]
    ​ ​ ​ ​ ​ ​ ​ ​ --guild [guild] **Only the bot owner can use this**

    **Scope** is one of the following:
    ​ ​ ​ ​ Global
    ​ ​ ​ ​ Guild
    ​ ​ ​ ​ User

    **Author** can be one of the following:
    ​ ​ ​ ​ User ID
    ​ ​ ​ ​ User Mention
    ​ ​ ​ ​ User Name#123

    **Guild** can be one of the following:
    ​ ​ ​ ​ Guild ID
    ​ ​ ​ ​ Exact guild name

    Example use:
    ​ ​ ​ ​ [p]playlist upload
    ​ ​ ​ ​ [p]playlist upload --scope Global
    ​ ​ ​ ​ [p]playlist upload --scope User
    """
    if scope_data is None:
        scope_data = [PlaylistScope.GUILD.value, ctx.author, ctx.guild, False]
    scope, author, guild, specified_user = scope_data
    temp_playlist = FakePlaylist(author.id, scope)
    if not await self.can_manage_playlist(scope, temp_playlist, ctx, author, guild):
        return

    if not await self._playlist_check(ctx):
        return
    player = lavalink.get_player(ctx.guild.id)

    await self._embed_msg(
        ctx,
        title=_(
            "Please upload the playlist file. Any other message will cancel this operation."
        ),
    )

    try:
        file_message = await ctx.bot.wait_for(
            "message", timeout=30.0, check=MessagePredicate.same_context(ctx)
        )
    except asyncio.TimeoutError:
        return await self._embed_msg(ctx, title=_("No file detected, try again later."))
    try:
        file_url = file_message.attachments[0].url
    except IndexError:
        return await self._embed_msg(ctx, title=_("Upload cancelled."))
    file_suffix = file_url.rsplit(".", 1)[1]
    if file_suffix != "txt":
        return await self._embed_msg(
            ctx, title=_("Only Red playlist files can be uploaded.")
        )
    try:
        async with self.session.request("GET", file_url) as r:
            uploaded_playlist = await r.json(
                content_type="text/plain", encoding="utf-8"
            )
    except UnicodeDecodeError:
        return await self._embed_msg(ctx, title=_("Not a valid playlist file."))

    new_schema = uploaded_playlist.get("schema", 1) >= 2
    version = uploaded_playlist.get("version", "v2")

    if new_schema and version == "v3":
        uploaded_playlist_url = uploaded_playlist.get("playlist_url", None)
        track_list = uploaded_playlist.get("tracks", [])
    else:
        uploaded_playlist_url = uploaded_playlist.get("link", None)
        track_list = uploaded_playlist.get("playlist", [])

    uploaded_playlist_name = uploaded_playlist.get(
        "name", (file_url.split("/")[6]).split(".")[0]
    )
    if (
        not uploaded_playlist_url
        or not match_yt_playlist(uploaded_playlist_url)
        or not (
            await self.music_cache.lavalink_query(
                ctx,
                player,
                audio_dataclasses.Query.process_input(uploaded_playlist_url),
            )
        )[0].tracks
    ):
        if version == "v3":
            return await self._load_v3_playlist(
                ctx,
                scope,
                uploaded_playlist_name,
                uploaded_playlist_url,
                track_list,
                author,
                guild,
            )
        return await self._load_v2_playlist(
            ctx,
            track_list,
            player,
            uploaded_playlist_url,
            uploaded_playlist_name,
            scope,
            author,
            guild,
        )
    return await ctx.invoke(
        self._playlist_save,
        playlist_name=uploaded_playlist_name,
        playlist_url=uploaded_playlist_url,
        scope_data=(scope, author, guild, specified_user),
    )