So I made this function that works, but how can I make the message update every second. I've tried to use setInterval(countdownTimer(), 1000)
, but it doesn't work. Here is my code!
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()
}