我当时正在编写机器人程序,所以我想从某个时间开始进行实时倒计时。我有正确的时间,但是我有一个问题。我无法编辑该消息,以便显示剩余时间。这是我的当前代码:
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', value: `${time} Seconds Left!` },
)
message.edit(Edit)
}
module.exports.help = {
name: "v2time"
};
如果有人可以提供帮助,将会很有帮助。谢谢。
答案 0 :(得分:0)
编辑邮件时,需要提供要发送的完整邮件。当前,由于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
)