# Buggy code
async def _eval(self, ctx, *, body: str):
    """Execute asynchronous code.

    This command wraps code into the body of an async function and then
    calls and awaits it. The bot will respond with anything printed to
    stdout, as well as the return value of the function.

    The code can be within a codeblock, inline code or neither, as long
    as they are not mixed and they are formatted correctly.

    Environment Variables:
        ctx      - command invokation context
        bot      - bot object
        channel  - the current channel object
        author   - command author's member object
        message  - the command's message object
        discord  - discord.py library
        commands - redbot.core.commands
        _        - The result of the last dev command.
    """
    env = {
        "bot": ctx.bot,
        "ctx": ctx,
        "channel": ctx.channel,
        "author": ctx.author,
        "guild": ctx.guild,
        "message": ctx.message,
        "discord": discord,
        "commands": commands,
        "_": self._last_result,
    }

    body = self.cleanup_code(body)
    stdout = io.StringIO()

    to_compile = "async def func():\n%s" % textwrap.indent(body, "  ")

    try:
        exec(to_compile, env)
    except SyntaxError as e:
        return await ctx.send(self.get_syntax_error(e))

    func = env["func"]
    result = None
    try:
        with redirect_stdout(stdout):
            result = await func()
    except:
        printed = "{}{}".format(stdout.getvalue(), traceback.format_exc())
    else:
        printed = stdout.getvalue()
        await ctx.tick()

    if result is not None:
        self._last_result = result
        msg = "{}{}".format(printed, result)
    else:
        msg = printed
    api_keys = await ctx.bot._config.api_tokens()
    msg = self.sanitize_output(ctx, api_keys, msg)

    await ctx.send_interactive(self.get_pages(msg), box_lang="py")


# Traceback (AttributeError)
Traceback (most recent call last):
File "c:\python37\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
ret = await coro(*args, **kwargs)
File "c:\python37\lib\site-packages\redbot\core\core_commands.py", line 334, in uptime
since = ctx.bot.uptime.strftime("%Y-%m-%d %H:%M:%S")
AttributeError: 'Red' object has no attribute 'uptime'

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

Traceback (most recent call last):
File "c:\python37\lib\site-packages\discord\ext\commands\bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "c:\python37\lib\site-packages\discord\ext\commands\core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "c:\python37\lib\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: AttributeError: 'Red' object has no attribute 'uptime'

# Fixed code
async def _eval(self, ctx, *, body: str):
    """Execute asynchronous code.

    This command wraps code into the body of an async function and then
    calls and awaits it. The bot will respond with anything printed to
    stdout, as well as the return value of the function.

    The code can be within a codeblock, inline code or neither, as long
    as they are not mixed and they are formatted correctly.

    Environment Variables:
        ctx      - command invokation context
        bot      - bot object
        channel  - the current channel object
        author   - command author's member object
        message  - the command's message object
        discord  - discord.py library
        commands - redbot.core.commands
        _        - The result of the last dev command.
    """
    env = {
        "bot": ctx.bot,
        "ctx": ctx,
        "channel": ctx.channel,
        "author": ctx.author,
        "guild": ctx.guild,
        "message": ctx.message,
        "discord": discord,
        "commands": commands,
        "_": self._last_result,
    }

    body = self.cleanup_code(body)
    stdout = io.StringIO()

    to_compile = "async def func():\n%s" % textwrap.indent(body, "  ")

    try:
        exec(to_compile, env)
    except SyntaxError as e:
        return await ctx.send(self.get_syntax_error(e))

    func = env["func"]
    result = None
    try:
        with redirect_stdout(stdout):
            result = await func()
    except:
        printed = "{}{}".format(stdout.getvalue(), traceback.format_exc())
    else:
        printed = stdout.getvalue()
        await ctx.tick()

    if result is not None:
        self._last_result = result
        msg = "{}{}".format(printed, result)
    else:
        msg = printed
    msg = self.sanitize_output(ctx, msg)

    await ctx.send_interactive(self.get_pages(msg), box_lang="py")