def _eval(self, ctx, *, code: str):
"""Run eval() on an input."""
code = code.strip('` ')
python = '```py\n{0}\n```'
env = self.env(ctx)
try:
result = eval(code, env)
if inspect.isawaitable(result):
result = await result
result = str(result)[:1014]
color = 0x00FF00
field = {
'inline': False,
'name': 'Yielded result:',
'value': python.format(result)
}
except Exception as e:
color = 0xFF0000
field = {
'inline': False,
'name': 'Yielded exception "{0.__name__}":'.format(type(e)),
'value': '{0} '.format(e)
}
embed = discord.Embed(title="Eval on:", description=python.format(code), color=color)
embed.add_field(**field)
await ctx.send(embed=embed)
评论列表
文章目录