简体   繁体   English

Discord.JS 消息编辑

[英]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.如果机器人由于某种原因断开连接,他将丢失 msgReference。 Because of that, I saved it to DB.因此,我将其保存到 DB。 How to create a message again because Message (object) in Discord.JS have a private constructor?如何再次创建消息,因为 Discord.JS 中的消息(对象)有一个私有构造函数?

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.这样,您可以随时使用client.msgRef.edit(...)

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

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