# Buggy code
async def _get_correct_playlist_id(
    self,
    context: commands.Context,
    matches: dict,
    scope: str,
    author: discord.User,
    guild: discord.Guild,
    specified_user: bool = False,
) -> Tuple[Optional[int], str]:
    """
    Parameters
    ----------
    context: commands.Context
        The context in which this is being called.
    matches: dict
        A dict of the matches found where key is scope and value is matches.
    scope:str
        The custom config scope. A value from :code:`PlaylistScope`.
    author: discord.User
        The user.
    guild: discord.Guild
        The guild.
    specified_user: bool
        Whether or not a user ID was specified via argparse.
    Returns
    -------
    Tuple[Optional[int], str]
        Tuple of Playlist ID or None if none found and original user input.
    Raises
    ------
    `TooManyMatches`
        When more than 10 matches are found or
        When multiple matches are found but none is selected.

    """
    original_input = matches.get("arg")
    correct_scope_matches = matches.get(scope)
    guild_to_query = guild.id
    user_to_query = author.id
    if not correct_scope_matches:
        return None, original_input
    if scope == PlaylistScope.USER.value:
        correct_scope_matches = [
            (i[2]["id"], i[2]["name"], len(i[2]["tracks"]), i[2]["author"])
            for i in correct_scope_matches
            if str(user_to_query) == i[0]
        ]
    elif scope == PlaylistScope.GUILD.value:
        if specified_user:
            correct_scope_matches = [
                (i[2]["id"], i[2]["name"], len(i[2]["tracks"]), i[2]["author"])
                for i in correct_scope_matches
                if str(guild_to_query) == i[0] and i[2]["author"] == user_to_query
            ]
        else:
            correct_scope_matches = [
                (i[2]["id"], i[2]["name"], len(i[2]["tracks"]), i[2]["author"])
                for i in correct_scope_matches
                if str(guild_to_query) == i[0]
            ]
    else:
        if specified_user:
            correct_scope_matches = [
                (i[2]["id"], i[2]["name"], len(i[2]["tracks"]), i[2]["author"])
                for i in correct_scope_matches
                if i[2]["author"] == user_to_query
            ]
        else:
            correct_scope_matches = [
                (i[2]["id"], i[2]["name"], len(i[2]["tracks"]), i[2]["author"])
                for i in correct_scope_matches
            ]
    match_count = len(correct_scope_matches)
    # We done all the trimming we can with the info available time to ask the user
    if match_count > 10:
        if original_input.isnumeric():
            arg = int(original_input)
            correct_scope_matches = [
                (i, n, t, a) for i, n, t, a in correct_scope_matches if i == arg
            ]
        if match_count > 10:
            raise TooManyMatches(
                f"{match_count} playlists match {original_input}: "
                f"Please try to be more specific, or use the playlist ID."
            )
    elif match_count == 1:
        return correct_scope_matches[0][0], original_input
    elif match_count == 0:
        return None, original_input

    # TODO : Convert this section to a new paged reaction menu when Toby Menus are Merged
    pos_len = 3
    playlists = f"{'#':{pos_len}}\n"

    for number, (pid, pname, ptracks, pauthor) in enumerate(correct_scope_matches, 1):
        author = self.bot.get_user(pauthor) or "Unknown"
        line = (
            f"{number}."
            f"    <{pname}>\n"
            f" - Scope:  < {humanize_scope(scope)} >\n"
            f" - ID:     < {pid} >\n"
            f" - Tracks: < {ptracks} >\n"
            f" - Author: < {author} >\n\n"
        )
        playlists += line

    embed = discord.Embed(
        title="Playlists found, which one would you like?",
        description=box(playlists, lang="md"),
        colour=await context.embed_colour(),
    )
    msg = await context.send(embed=embed)
    avaliable_emojis = ReactionPredicate.NUMBER_EMOJIS[1:]
    avaliable_emojis.append("🔟")
    emojis = avaliable_emojis[: len(correct_scope_matches)]
    emojis.append("❌")
    start_adding_reactions(msg, emojis)
    pred = ReactionPredicate.with_emojis(emojis, msg, user=context.author)
    try:
        await context.bot.wait_for("reaction_add", check=pred, timeout=60)
    except asyncio.TimeoutError:
        with contextlib.suppress(discord.HTTPException):
            await msg.delete()
        raise TooManyMatches(
            "Too many matches found and you did not select which one you wanted."
        )
    if emojis[pred.result] == "❌":
        with contextlib.suppress(discord.HTTPException):
            await msg.delete()
        raise TooManyMatches(
            "Too many matches found and you did not select which one you wanted."
        )
    with contextlib.suppress(discord.HTTPException):
        await msg.delete()
    return correct_scope_matches[pred.result][0], original_input


# 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 _get_correct_playlist_id(
    self,
    context: commands.Context,
    matches: MutableMapping,
    scope: str,
    author: discord.User,
    guild: discord.Guild,
    specified_user: bool = False,
) -> Tuple[Optional[int], str]:
    """
    Parameters
    ----------
    context: commands.Context
        The context in which this is being called.
    matches: dict
        A dict of the matches found where key is scope and value is matches.
    scope:str
        The custom config scope. A value from :code:`PlaylistScope`.
    author: discord.User
        The user.
    guild: discord.Guild
        The guild.
    specified_user: bool
        Whether or not a user ID was specified via argparse.
    Returns
    -------
    Tuple[Optional[int], str]
        Tuple of Playlist ID or None if none found and original user input.
    Raises
    ------
    `TooManyMatches`
        When more than 10 matches are found or
        When multiple matches are found but none is selected.

    """
    correct_scope_matches: List[Playlist]
    original_input = matches.get("arg")
    correct_scope_matches_temp: MutableMapping = matches.get(scope)
    guild_to_query = guild.id
    user_to_query = author.id
    if not correct_scope_matches_temp:
        return None, original_input
    if scope == PlaylistScope.USER.value:
        correct_scope_matches = [
            p for p in correct_scope_matches_temp if user_to_query == p.scope_id
        ]
    elif scope == PlaylistScope.GUILD.value:
        if specified_user:
            correct_scope_matches = [
                p
                for p in correct_scope_matches_temp
                if guild_to_query == p.scope_id and p.author == user_to_query
            ]
        else:
            correct_scope_matches = [
                p for p in correct_scope_matches_temp if guild_to_query == p.scope_id
            ]
    else:
        if specified_user:
            correct_scope_matches = [
                p for p in correct_scope_matches_temp if p.author == user_to_query
            ]
        else:
            correct_scope_matches = [p for p in correct_scope_matches_temp]

    match_count = len(correct_scope_matches)
    if match_count > 1:
        correct_scope_matches2 = [
            p for p in correct_scope_matches if p.name == str(original_input).strip()
        ]
        if correct_scope_matches2:
            correct_scope_matches = correct_scope_matches2
        elif original_input.isnumeric():
            arg = int(original_input)
            correct_scope_matches3 = [p for p in correct_scope_matches if p.id == arg]
            if correct_scope_matches3:
                correct_scope_matches = correct_scope_matches3
    match_count = len(correct_scope_matches)
    # We done all the trimming we can with the info available time to ask the user
    if match_count > 10:
        if original_input.isnumeric():
            arg = int(original_input)
            correct_scope_matches = [p for p in correct_scope_matches if p.id == arg]
        if match_count > 10:
            raise TooManyMatches(
                _(
                    "{match_count} playlists match {original_input}: "
                    "Please try to be more specific, or use the playlist ID."
                ).format(match_count=match_count, original_input=original_input)
            )
    elif match_count == 1:
        return correct_scope_matches[0].id, original_input
    elif match_count == 0:
        return None, original_input

    # TODO : Convert this section to a new paged reaction menu when Toby Menus are Merged
    pos_len = 3
    playlists = f"{'#':{pos_len}}\n"
    number = 0
    for number, playlist in enumerate(correct_scope_matches, 1):
        author = self.bot.get_user(playlist.author) or playlist.author or _("Unknown")
        line = _(
            "{number}."
            "    <{playlist.name}>\n"
            " - Scope:  < {scope} >\n"
            " - ID:     < {playlist.id} >\n"
            " - Tracks: < {tracks} >\n"
            " - Author: < {author} >\n\n"
        ).format(
            number=number,
            playlist=playlist,
            scope=humanize_scope(scope),
            tracks=len(playlist.tracks),
            author=author,
        )
        playlists += line

    embed = discord.Embed(
        title=_("{playlists} playlists found, which one would you like?").format(
            playlists=number
        ),
        description=box(playlists, lang="md"),
        colour=await context.embed_colour(),
    )
    msg = await context.send(embed=embed)
    avaliable_emojis = ReactionPredicate.NUMBER_EMOJIS[1:]
    avaliable_emojis.append("🔟")
    emojis = avaliable_emojis[: len(correct_scope_matches)]
    emojis.append("\N{CROSS MARK}")
    start_adding_reactions(msg, emojis)
    pred = ReactionPredicate.with_emojis(emojis, msg, user=context.author)
    try:
        await context.bot.wait_for("reaction_add", check=pred, timeout=60)
    except asyncio.TimeoutError:
        with contextlib.suppress(discord.HTTPException):
            await msg.delete()
        raise TooManyMatches(
            _("Too many matches found and you did not select which one you wanted.")
        )
    if emojis[pred.result] == "\N{CROSS MARK}":
        with contextlib.suppress(discord.HTTPException):
            await msg.delete()
        raise TooManyMatches(
            _("Too many matches found and you did not select which one you wanted.")
        )
    with contextlib.suppress(discord.HTTPException):
        await msg.delete()
    return correct_scope_matches[pred.result].id, original_input