def do(message: discord.Message, python_code: Annotate.Code):
""" Execute python code. """
code_globals.update(dict(message=message, client=client,
author=message.author, server=message.server, channel=message.channel))
# Create an async function so that we can await it using the result of eval
python_code = "async def do_session():\n " + "\n ".join(line for line in python_code.split("\n"))
try:
exec(python_code, code_globals)
except SyntaxError as e:
await client.say(message, "```" + utils.format_syntax_error(e) + "```")
return
before = datetime.now()
try:
result = await eval("do_session()", code_globals)
except Exception as e:
await client.say(message, "```" + utils.format_exception(e) + "```")
else:
if result:
await send_result(message.channel, result, datetime.now() - before)
评论列表
文章目录