简体   繁体   中英

Discord.JS Message Edit

I want to edit the message over and over again. So I made variable

this.msgRef = await channel.send({ embeds: [embedMessage] });

If I want to edit I use

this.msgRef.edit(...)

If the bot for some reason disconnects, he will lose msgReference. Because of that, I saved it to DB. How to create a message again because Message (object) in Discord.JS have a private constructor?

If you want to get the message again, you can simply fetch the channel's messages every time you bot connects (on the ready event for example) like so

client.on('ready', () =>{
  const messages = await channel.messages.fetch()
  client.msgRef = messages.find(msg => msg.author.id === client.user.id
    && msg.embeds[0]
   // Etc.. Add as many conditions to make sure you choose the right message
);
})

This way, use client.msgRef.edit(...) whenever you want.

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