简体   繁体   中英

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:

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM