I created a function that's functioning properly, but I'm looking to update the message every second. Previously, I attempted using
setInterval(countdownTimer(), 1000)
, however, it was unsuccessful. Below is my code snippet!
let x = await msg.channel.send('Calculating...')
async function countdownTimer() {
const difference = +new Date("2020-06-01") - +new Date();
let remaining = "Time's up!";
if (difference > 0) {
const parts = {
days: Math.floor(difference / (1000 * 60 * 60 * 24)),
hours: Math.floor((difference / (1000 * 60 * 60)) % 24),
minutes: Math.floor((difference / 1000 / 60) % 60),
seconds: Math.floor((difference / 1000) % 60)
};
remaining = Object.keys(parts).map(part => {
if (!parts[part]) return;
return `${parts[part]} ${part}`;
}).join(" ");
}
setInterval(() => {
x.edit(remaining);
}, 1000);
}
countdownTimer()
}