因此,我试图构建一个不和谐的机器人,我想要拥有的功能之一是引用以前的消息并从中提取数据。我已经存储了我想要引用的消息ID,但是我似乎找不到如何从它的ID中提取消息对象。
if split[0] == 'ref':
if (len(split) < 2):
await message.channel.send("!ref,poll or sg,id number")
if (len(split) == 3):
if split[1] == "poll":
for x in db["poll"]:
if x[1] == message.guild.id and x[0] == split[2]:
original = await discord.utils.get(message.channel, message_id=int(split[2]))
await message.channel.send(original.content)
我一直对原始变量使用错误的语法,但我无法理解它
我试着用
original = await message.channel.fetch_message(int(split[2]))
并得到了
Bot is online as *******
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 277, in on_message
original = await message.channel.fetch_message(int(split[2]))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 1132, in fetch_message
data = await self._state.http.get_message(channel.id, id)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 250, in request
raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
我也有我想要的频道的ID
发布于 2021-09-21 00:29:01
您可以直接获取消息,只需要消息所在的message-id
和channel
。
您可以通过这样的方式在original
中获取“message.channel
”消息:
original = await message.channel.fetch_message(int(split[2]))
如果您没有通道对象,并且只有通道id,那么只需要bot.get_channel
。看起来是这样的:
channel = bot.get_channel(mychannelid)
资料来源
https://stackoverflow.com/questions/69262035
复制相似问题