# Buggy code
async def debug(self, ctx, *, code):
    """Evaluate a statement of python code.

    The bot will always respond with the return value of the code.
    If the return value of the code is a coroutine, it will be awaited,
    and the result of that will be the bot's response.

    Note: Only one statement may be evaluated. Using await, yield or
    similar restricted keywords will result in a syntax error. For multiple
    lines or asynchronous code, see [p]repl or [p]eval.

    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,
    }

    code = self.cleanup_code(code)

    try:
        result = eval(code, env)
    except SyntaxError as e:
        await ctx.send(self.get_syntax_error(e))
        return
    except Exception as e:
        await ctx.send(box("{}: {!s}".format(type(e).__name__, e), lang="py"))
        return

    if inspect.isawaitable(result):
        result = await result

    self._last_result = result

    api_keys = await ctx.bot._config.api_tokens()
    result = self.sanitize_output(ctx, api_keys, str(result))

    await ctx.send_interactive(self.get_pages(result), 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 debug(self, ctx, *, code):
    """Evaluate a statement of python code.

    The bot will always respond with the return value of the code.
    If the return value of the code is a coroutine, it will be awaited,
    and the result of that will be the bot's response.

    Note: Only one statement may be evaluated. Using await, yield or
    similar restricted keywords will result in a syntax error. For multiple
    lines or asynchronous code, see [p]repl or [p]eval.

    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,
    }

    code = self.cleanup_code(code)

    try:
        result = eval(code, env)
    except SyntaxError as e:
        await ctx.send(self.get_syntax_error(e))
        return
    except Exception as e:
        await ctx.send(box("{}: {!s}".format(type(e).__name__, e), lang="py"))
        return

    if inspect.isawaitable(result):
        result = await result

    self._last_result = result
    result = self.sanitize_output(ctx, str(result))

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