discord.py - 打印错误代码不起作用(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)
解决方案
我发现了另一个 Stackoverflow 问题(Discord.py-Rewrite Sending an Error message when there is an unknown command or other error)有答案。看起来,没有必要像我的代码那样使命令复杂化。
推荐阅读
- python - 如何进行视频取景?
- python - 使用 Presto jar 加载 pyspark shell 时无法使用 pyspark 的 S3 功能
- python - 如何根据另一个数据框中的列的 value_counts 创建一个新的数据框,但在其他列上具有某些条件?
- python-3.x - 将附件中的图像保存在 couchdb
- c# - .NET 多线程调用 Web 服务
- c++ - 致命错误:在 Mac 中的 VScode 中的 C++ 中找不到“plist/Node.h”文件错误
- php - 如何使用 PHP_EOL?
- reactjs - 如何在 React 材料中的列表项之间创建一个空格
- node.js - MySQL数据库连接
- node.js - 如何在节点js中合并其他表的响应属性