首页 > 解决方案 > 带有用户令牌的 fetch_message(id)

问题描述

使用await fetch_message(id)用户令牌

client.run((token), bot=False)

我试图让一个机器人使用用户的令牌通过我尝试使用的 id 来响应消息,await fetch_message(id)但我得到了:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\edgar\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\edgar\Desktop\bot\bot.py", line 20, in on_message
    msg = await channel.fetch_message(826185450141253682)
  File "C:\Users\edgar\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\abc.py", line 1002, in fetch_message
    data = await self._state.http.get_message(channel.id, id)
  File "C:\Users\edgar\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.py", line 241, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 20002): Only bots can use this endpoint

标签: discord.py

解决方案


注意此解决方法仅在您的 selfbot 在发送消息的位置运行时才有效。

您可以使用 discord 客户端的 cached_mesages 属性。

messages = client.cached_messages
# and then use the utils.get function to seek for the id in this list
message = discord.utils.get(messages, id=id_to_seek)

#  utils.get() returns None if message not found
#  else it returnes a normal Message object you can work with.

我从未在 selfbot 上尝试过,但这会阻止您进行 API 调用,并且应该可以按预期工作。


推荐阅读