# Buggy code
async def repl(self, ctx):
    """Open an interactive REPL.

    The REPL will only recognise code as messages which start with a
    backtick. This includes codeblocks, and as such multiple lines can be
    evaluated.

    You may not await any code in this REPL unless you define it inside an
    async function.
    """
    variables = {
        "ctx": ctx,
        "bot": ctx.bot,
        "message": ctx.message,
        "guild": ctx.guild,
        "channel": ctx.channel,
        "author": ctx.author,
        "_": None,
    }

    if ctx.channel.id in self.sessions:
        await ctx.send(
            _("Already running a REPL session in this channel. Exit it with `quit`.")
        )
        return

    self.sessions.add(ctx.channel.id)
    await ctx.send(_("Enter code to execute or evaluate. `exit()` or `quit` to exit."))

    while True:
        response = await ctx.bot.wait_for(
            "message", check=MessagePredicate.regex(r"^`", ctx)
        )

        cleaned = self.cleanup_code(response.content)

        if cleaned in ("quit", "exit", "exit()"):
            await ctx.send(_("Exiting."))
            self.sessions.remove(ctx.channel.id)
            return

        executor = exec
        if cleaned.count("\n") == 0:
            # single statement, potentially 'eval'
            try:
                code = compile(cleaned, "<repl session>", "eval")
            except SyntaxError:
                pass
            else:
                executor = eval

        if executor is exec:
            try:
                code = compile(cleaned, "<repl session>", "exec")
            except SyntaxError as e:
                await ctx.send(self.get_syntax_error(e))
                continue

        variables["message"] = response

        stdout = io.StringIO()

        msg = ""

        try:
            with redirect_stdout(stdout):
                result = executor(code, variables)
                if inspect.isawaitable(result):
                    result = await result
        except:
            value = stdout.getvalue()
            msg = "{}{}".format(value, traceback.format_exc())
        else:
            value = stdout.getvalue()
            if result is not None:
                msg = "{}{}".format(value, result)
                variables["_"] = result
            elif value:
                msg = "{}".format(value)

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

        try:
            await ctx.send_interactive(self.get_pages(msg), box_lang="py")
        except discord.Forbidden:
            pass
        except discord.HTTPException as e:
            await ctx.send(_("Unexpected error: `{}`").format(e))


# 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 repl(self, ctx):
    """Open an interactive REPL.

    The REPL will only recognise code as messages which start with a
    backtick. This includes codeblocks, and as such multiple lines can be
    evaluated.

    You may not await any code in this REPL unless you define it inside an
    async function.
    """
    variables = {
        "ctx": ctx,
        "bot": ctx.bot,
        "message": ctx.message,
        "guild": ctx.guild,
        "channel": ctx.channel,
        "author": ctx.author,
        "_": None,
    }

    if ctx.channel.id in self.sessions:
        await ctx.send(
            _("Already running a REPL session in this channel. Exit it with `quit`.")
        )
        return

    self.sessions.add(ctx.channel.id)
    await ctx.send(_("Enter code to execute or evaluate. `exit()` or `quit` to exit."))

    while True:
        response = await ctx.bot.wait_for(
            "message", check=MessagePredicate.regex(r"^`", ctx)
        )

        cleaned = self.cleanup_code(response.content)

        if cleaned in ("quit", "exit", "exit()"):
            await ctx.send(_("Exiting."))
            self.sessions.remove(ctx.channel.id)
            return

        executor = exec
        if cleaned.count("\n") == 0:
            # single statement, potentially 'eval'
            try:
                code = compile(cleaned, "<repl session>", "eval")
            except SyntaxError:
                pass
            else:
                executor = eval

        if executor is exec:
            try:
                code = compile(cleaned, "<repl session>", "exec")
            except SyntaxError as e:
                await ctx.send(self.get_syntax_error(e))
                continue

        variables["message"] = response

        stdout = io.StringIO()

        msg = ""

        try:
            with redirect_stdout(stdout):
                result = executor(code, variables)
                if inspect.isawaitable(result):
                    result = await result
        except:
            value = stdout.getvalue()
            msg = "{}{}".format(value, traceback.format_exc())
        else:
            value = stdout.getvalue()
            if result is not None:
                msg = "{}{}".format(value, result)
                variables["_"] = result
            elif value:
                msg = "{}".format(value)

        msg = self.sanitize_output(ctx, msg)

        try:
            await ctx.send_interactive(self.get_pages(msg), box_lang="py")
        except discord.Forbidden:
            pass
        except discord.HTTPException as e:
            await ctx.send(_("Unexpected error: `{}`").format(e))