# Buggy code
async def global_unique_guild_finder(ctx: commands.Context, arg: str) -> discord.Guild:
    bot: commands.Bot = ctx.bot
    _id = _match_id(arg)

    if _id is not None:
        guild: discord.Guild = bot.get_guild(_id)
        if guild is not None:
            return guild

    maybe_matches = []
    for obj in bot.guilds:
        if obj.name == arg or str(obj) == arg:
            maybe_matches.append(obj)

    if not maybe_matches:
        raise NoMatchesFound(
            _(
                '"{arg}" was not found. It must be the ID or '
                "complete name of a server which the bot can see."
            ).format(arg=arg)
        )
    elif len(maybe_matches) == 1:
        return maybe_matches[0]
    else:
        raise TooManyMatches(
            _(
                '"{arg}" does not refer to a unique server. '
                "Please use the ID for the server you're trying to specify."
            ).format(arg=arg)
        )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/bot/botenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "/home/bot/botenv/lib/python3.8/site-packages/redbot/cogs/audio/audio.py", line 4937, in _playlist_list
playlists = await get_all_playlist(scope, self.bot, guild, author, specified_user)
File "/home/bot/botenv/lib/python3.8/site-packages/redbot/cogs/audio/playlists.py", line 475, in get_all_playlist
scope_standard, scope_id = _prepare_config_scope(scope, author, guild)
File "/home/bot/botenv/lib/python3.8/site-packages/redbot/cogs/audio/playlists.py", line 86, in _prepare_config_scope
scope = standardize_scope(scope)
File "/home/bot/botenv/lib/python3.8/site-packages/redbot/cogs/audio/playlists.py", line 62, in standardize_scope
scope = scope.upper()
AttributeError: 'NoneType' object has no attribute 'upper'

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

Traceback (most recent call last):
File "/home/bot/botenv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "/home/bot/botenv/lib/python3.8/site-packages/redbot/core/commands/commands.py", line 799, in invoke
await super().invoke(ctx)
File "/home/bot/botenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1234, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "/home/bot/botenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/bot/botenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'upper'

# Fixed code
async def global_unique_guild_finder(ctx: commands.Context, arg: str) -> discord.Guild:
    bot: Red = ctx.bot
    _id = _match_id(arg)

    if _id is not None:
        guild: discord.Guild = bot.get_guild(_id)
        if guild is not None:
            return guild

    maybe_matches = []
    async for obj in AsyncIter(bot.guilds):
        if obj.name == arg or str(obj) == arg:
            maybe_matches.append(obj)

    if not maybe_matches:
        raise NoMatchesFound(
            _(
                '"{arg}" was not found. It must be the ID or '
                "complete name of a server which the bot can see."
            ).format(arg=arg)
        )
    elif len(maybe_matches) == 1:
        return maybe_matches[0]
    else:
        raise TooManyMatches(
            _(
                '"{arg}" does not refer to a unique server. '
                "Please use the ID for the server you're trying to specify."
            ).format(arg=arg)
        )