尝试将频道名称设置为当前 UTC 时间时,我遇到了一些意外结果。
下面的代码运行但仅每十分钟更新一次频道名称(它每 30 秒尝试一次,没有错误)。当它确实更新频道名称时,它实际上连续更新了 4 次,最终落后 1 分钟。
编码:
var job = Cron.schedule("*/30 * * * * *", function () {
let newName = date.format(new Date(), 'HH:mm UTC', true);
let UTCChan = client.channels.cache.get('<Chan ID>');
console.log(`${date.format(new Date(), 'HH:mm:ss', true)} - Channel's current name is ${UTCChan.name} - New name should be ${newName}`);
UTCChan.edit({ name: newName })
.then(newChannel => console.log(`Channel's new name is ${newChannel.name}`))
.catch(console.error);
}, {
scheduled: true
});
job.start();
这是控制台窗口的输出:
14:41:30 - Channel's current name is 14:30 UTC - New name should be 14:41 UTC
Channel's new name is 14:41 UTC
Channel's new name is 14:41 UTC
Channel's new name is 14:40 UTC
Channel's new name is 14:40 UTC
14:42:00 - Channel's current name is 14:40 UTC - New name should be 14:42 UTC
14:42:30 - Channel's current name is 14:40 UTC - New name should be 14:42 UTC
14:43:00 - Channel's current name is 14:40 UTC - New name should be 14:43 UTC
14:43:30 - Channel's current name is 14:40 UTC - New name should be 14:43 UTC
14:44:00 - Channel's current name is 14:40 UTC - New name should be 14:44 UTC
14:44:30 - Channel's current name is 14:40 UTC - New name should be 14:44 UTC
14:45:00 - Channel's current name is 14:40 UTC - New name should be 14:45 UTC
14:45:30 - Channel's current name is 14:40 UTC - New name should be 14:45 UTC
14:46:00 - Channel's current name is 14:40 UTC - New name should be 14:46 UTC