python - discord.py:如何获取错误的实际路径?
问题描述
我正在使用该事件on_error
,并试图获取错误的实际路径。例如,有一个错误,如discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
. 回溯中有多个文件路径,我想获取错误实际所在的文件路径。
我试过了:
import traceback
import sys
@client.event
async def on_error(event, *args, **kwargs):
error = sys.exc_info()[1]
print(error.__traceback__.tb_frame.f_code.co_filename)
输出是:C:\Users\Andrin\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py
这不是错误实际来自的文件。错误是:
Traceback (most recent call last):
File "C:\Users\Andrin\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:/Users/Andrin/Documents/GitHub/RLH-Moderator/Python/DiscordController.py", line 183, in on_message
await OnMessage.on_message(client, message, user_input)
File "C:\Users\Andrin\Documents\GitHub\RLH-Moderator\Python\Events\Message_Events\OnMessage.py", line 33, in on_message
message = await message.channel.fetch_message(213123213)
File "C:\Users\Andrin\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\abc.py", line 1131, in fetch_message
data = await self._state.http.get_message(channel.id, id)
File "C:\Users\Andrin\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 250, in request
raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
我想得到那个:C:\Users\Andrin\Documents\GitHub\RLH-Moderator\Python\Events\Message_Events\OnMessage.py
解决方案
推荐阅读
- ios - 如何向 SCNProgram 提供自定义数据?
- python - 获取最常出现的字符串值?
- ssis - 比较相同 ssis 包的执行情况
- javascript - DataTables如何正确调用data.json
- javascript - 我有一个带有提交按钮的简单表单。如何使提交按钮和输入键提交表单?
- r - 在 R Shiny 中叠加图像
- jenkins - 根据 Jenkins 中的脚本输出或控制台输出发起电子邮件
- bash - 如何使用带有 echo 和 bc 命令的第二个管道?
- azure - 从 Powershell 脚本运行 Azure Runbook
- sql - SSIS 在更新期间挂起,有 300 万行