I'm trying to make a discord bot that accepts multi-line input, so that it can execute a python code. My code is the following:
@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
The thing is that this function can only take one-line input like:
b!python a=1;print(a)
However, I want to make the discord.py bot take this type of message: An example of a complete message is the following:
b!python
a = 1
print(a)
I want to accept a multi-line input and assign it to a variable in my code and execute it:
code = """a = 1
print(a)
"""
exec(message)
I have seen some bots execute python code like that but I have no idea how to do it without using *args, in which case it only accepts one-line code. Is there a way to accept multi-line input?