如何修复 Discord.py 中的未知消息 (404)

我的机器人使用 Discord.py 自动对新消息做出反应,并在 25 颗星后将它们添加到右舷。但是,在运行一段时间后会出现此错误:忽略 on_raw_reaction_add 中的异常


Ignoring exception in on_raw_reaction_add

Traceback (most recent call last):

  File "C:\Users\timpi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event

    await coro(*args, **kwargs)

  File ".\main.py", line 36, in on_raw_reaction_add

    message = await reactchannel.fetch_message(payload.message_id)

  File "C:\Users\timpi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\abc.py", line 935, in fetch_message

    data = await self._state.http.get_message(channel.id, id)

  File "C:\Users\timpi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 223, in request

    raise NotFound(r, data)

discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message

这是on_raw_reaction_add事件:


@bot.event

async def on_raw_reaction_add(payload):

    channel_id = int(config["channelIDMemephone"])

    reactchannel = bot.get_channel(channel_id)

    message = await reactchannel.fetch_message(payload.message_id)

    await star_post_check(message)


喵喵时光机
浏览 153回答 1
1回答

慕仙森

如果消息不在配置文件的频道中,则搜索该频道时将找不到它。您可以添加一个检查以确保您只与该频道中的消息进行交互:@bot.eventasync def on_raw_reaction_add(payload):    if payload.channel_id == int(config["channelIDMemephone"]):        reactchannel = bot.get_channel(payload.channel_id)        message = await reactchannel.fetch_message(payload.message_id)        await star_post_check(message)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python