首页 > 解决方案 > 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

标签: pythondiscord.py

解决方案


推荐阅读