如何解决连续编辑消息
我当时正在编写机器人程序,所以我想从某个时间开始进行实时倒计时。我有正确的时间,但是我有一个问题。我无法编辑该消息,以便显示剩余时间。这是我的当前代码:
module.exports.run = async (client,message,args) => {
let time = client.db.get(`time`)
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#ff74fc')
.setTitle('V2 Release Time')
.setDescription('This command will be showing the countdown until the V2 cafe releases! ')
.setThumbnail('https://media.discordapp.net/attachments/708130362122829876/746736868124524584/image0.jpg')
.addFields(
{ name: 'Time',value: `${time} Seconds Left!` },)
.setTimestamp()
.setFooter('Flamgo Bot');
return message.channel.send(exampleEmbed)
const Edit = new Discord.MessageEmbed()
.addFields(
{ name: 'Time',)
message.edit(Edit)
}
module.exports.help = {
name: "v2time"
};
如果有人可以提供帮助,将会很有帮助。谢谢。
解决方法
编辑邮件时,需要提供要发送的完整邮件。当前,由于Edit
是仅由1个“时间”字段组成的嵌入,因此消息将仅使用该字段进行更新,并且所有先前的字段和其他嵌入内容都将被删除。
尝试一下:
const createEmbed = time => new Discord.MessageEmbed()
.setColor('#ff74fc')
.setTitle('V2 Release Time')
.setDescription('This command will be showing the countdown until the V2 cafe releases! ')
.setThumbnail('https://media.discordapp.net/attachments/708130362122829876/746736868124524584/image0.jpg')
// addField can be used for adding a single field
.addField('Time',`${time} Seconds Left!`)
.setTimestamp()
.setFooter('Flamgo Bot');
// Usage:
message.channel.send(createdEmbed(client.db.get('time')));
message.edit(createEmbed(client.db.get('time')));
例如,如果您要不断更新此嵌入,可以执行以下操作:
/**
* The timestamp of the date that you're counting down to
* @type {number}
*/
const releaseDate = // ...
// Client#setInterval is the same is setInterval except that the interval is
// automatically cleared if the client is destroyed
client.setInterval(() =>
message.edit(createEmbed(Math.round((releaseDate - Date.now()) / 1000)))
.catch(console.error),1000
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。