首页 > 解决方案 > 打印错误代码不起作用(PyCharm,Python 3.8)

问题描述

我在 Stackoverflow 中找到了这段代码,它打印了任何错误消息。但它不会打印错误。只是说是否相关,PyCharm 说 Bot 没有属性 AppInfo。

代码:

@bot.event
async def on_error(event, *args, **kwargs):
    embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c)
    embed.add_field(name='Event', value=event)
    embed.description = '```py\n%s\n```' % traceback.format_exc()
    embed.timestamp = datetime.datetime.utcnow()
    await bot.AppInfo.owner.send(embed=embed)

标签: discord.pypython-3.8argskeyword-argument

解决方案


我发现了另一个 Stackoverflow 问题(Discord.py-Rewrite Sending an Error message when there is an unknown command or other error)有答案。看起来,没有必要像我的代码那样使命令复杂化。


推荐阅读