Python Discord.py多行输入

Python Discord.py多行输入,python,discord.py,Python,Discord.py,我正在尝试制作一个接受多行输入的discord bot,以便它可以执行python代码。我的代码如下: @bot.command(name="python", help="executes python script") async def python(ctx, *args): try: with Capturing() as output: #Capture output exec(" &quo

我正在尝试制作一个接受多行输入的discord bot,以便它可以执行python代码。我的代码如下:

@bot.command(name="python", help="executes python script")
async def python(ctx, *args):
    try:
        with Capturing() as output: #Capture output
            exec(" ".join(args).replace('"', "'"))
        # send captured output to thread
    except Exception as e:
        await ctx.send("```\n{}\n```".format(e)) # Send error message
b!python
a = 1
print(a)
问题是此函数只能接受一行输入,如:

b!python a=1;print(a)
但是,我想让discord.py bot接收以下类型的消息: 完整消息的示例如下所示:

@bot.command(name="python", help="executes python script")
async def python(ctx, *args):
    try:
        with Capturing() as output: #Capture output
            exec(" ".join(args).replace('"', "'"))
        # send captured output to thread
    except Exception as e:
        await ctx.send("```\n{}\n```".format(e)) # Send error message
b!python
a = 1
print(a)
我希望接受多行输入并将其分配给代码中的变量并执行它:

code = """a = 1
print(a)
"""
exec(message)
我见过一些机器人程序执行类似的python代码,但我不知道如何在不使用*args的情况下执行,在这种情况下,它只接受一行代码。有没有一种方法可以接受多行输入?

您可以使用向discord.py指示要将所有其余输入捕获为单个参数:

@bot.command(name="python", help="executes python script")
async def python(ctx, *, arg):
    try:
        exec(arg)
    except Exception as e:
        await ctx.send("```\n{}\n```".format(e)) # Send error message

你希望机器人如何知道输入的结束位置?我猜,消息何时结束。