尝试将频道名称设置为当前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