discord.py - 带有用户令牌的 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
解决方案
注意此解决方法仅在您的 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 调用,并且应该可以按预期工作。
推荐阅读
- javascript - VueJS(或 Vanilla JS)过滤结果的测试对象,包括二级搜索
- android - 如何设置默认 Chrome 自定义标签不必显示“打开方式”
- java - 用两个转义单个反斜杠 \
- postgresql - 无法创建共享内存段。失败的系统调用是 shmget。PostgreSQL MacOS 莫哈韦沙漠。符号链接的 postgres 数据目录
- search - 多个 dois 进入同一个查询以进行 scopus 搜索
- php - PrestaShopException.php 忽略修改
- javascript - 使用 BigNumber.toString 时使用 TypeScript 触发编译错误?
- javafx - 如何更改矩形的颜色?
- python - 如何在保留空格的同时删除包含字符串的系列中的非字母数字(英文)字符?
- javascript - 如何为各个国家添加超链接?AMCharts