简体   繁体   English

如何引用以前的机器人消息? (Discord.js v14)

[英]How to reference to a previous bot message? (Discord.js v14)

I want to change a specific message's embed after a while, but I am stuck at fetching the reference to this message correctly.我想在一段时间后更改特定消息的嵌入,但我一直无法正确获取对该消息的引用。 Can someone point me in the right direction?有人可以指出我正确的方向吗?

I first tried this:我首先尝试了这个:

const msgRef = await interaction.editReply({ embeds: [exampleEmbed_1] });
let todos = []
todos.push(msgRef)

But when I try to use the msgRef object to update the message with another embed:但是当我尝试使用 msgRef object 使用另一个嵌入更新消息时:

const message = todos[0]
await message.edit({ embeds: [exampleEmbed_2] });

I get an error:我收到一个错误:

TypeError: message.edit is not a function

I am bit confused at this point.在这一点上我有点困惑。 How can I properly fetch a specific message's reference to change the content later?如何正确获取特定消息的引用以稍后更改内容? Is there a way maybe to search for it via a message ID?有没有办法通过消息 ID 搜索它?

You can fetch it via message ID but you would also need the ID of the channel it was sent in, then you can use the Client.channels.fetch('channel id').messages.fetch('message id') method which will return the Message object if it exists.您可以通过消息 ID 获取它,但您还需要发送它的频道的 ID,然后您可以使用Client.channels.fetch('channel id').messages.fetch('message id')方法如果存在,将返回消息 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何向我的机器人在 v14 discord.js 中的所有 discord 服务器发送消息? - How would I send a message to all discord servers my bot is in v14 discord.js? 如何在 Discord.js v14(斜杠命令)中安排机器人消息? - How to schedule a bot message in Discord.js v14 (Slash commands)? 如何在 Discord.js v14 中创建只有用户和机器人可以看到的私人频道? - How to create a private channel only the user and the bot can see in Discord.js v14? Discord.js v14 如何处理按钮交互 - Discord.js v14 how to handle button interactions 如何从 Discord.js v14 中的消息中嵌入 - How to get a embed from a message in Discord.js v14 discord.js v14 试图做到这一点我的机器人状态将是机器人在其中的服务器数量 - discord.js v14 trying to do that my bot status will be the amount of servers that the bot is in them 如果斜线命令有效,我怎样才能让我的 discord.js v14 机器人停止说“应用程序没有响应”? - How can i get my discord.js v14 bot to stop saying "The application did not respond" if the slash command works? 从 Discord.js v14 中的机器人用户获取权限? - Get permissions from bot user in Discord.js v14? 检查机器人是否在特定通道 discord.js v14 中具有权限 - Check if bot has permissions in a specific channel discord.js v14 Discord.js V14 / 重启机器人后嵌入不发送 - Discord.js V14 / Embed doesn't send after restarting bot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM