I'm having some unexpected results when trying to set the name of a channel to the current UTC time.
The below code runs but only updates the channel name every ten minutes (it tries every 30 seconds without error). When it does update the channel name it actually updates it 4 times in a row and ends up being 1 minute behind.
The code:
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();
Here is the output from the console window:
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