How to configure the timer code more efficiently?

Viewed 41

When using this code, the message is updated every second, and then suddenly moves slowly or quickly in every five seconds. I want to make a more stable timer. What should I do?

const { Client, GatewayIntentBits, Collection } = require('discord.js');

module.exports = {
    name: "timer",
    async execute(message, args) {
        ggg=args.shift(1)
        let timecc = ggg*60
      const tic = await message.reply("⏳"+parseInt((timecc / 60)/60)+"h"+parseInt((timecc / 60)%60)+"m"+(timecc % 60)+"s")
      var timer = setInterval(() => {
          timecc --
          tic.edit({ content: "⏳"+parseInt((timecc / 60)/60)+"h"+parseInt((timecc / 60)%60)+"m"+(timecc % 60)+"s" })
          .catch(console.warn = () => {});
          
          if (timecc === 0) {
              clearInterval(timer);
              tic.edit({ content: "⌛"+"@everyone time out!" })
              .catch(console.warn = () => {});
              } 
}, 1000)
    }
}
1 Answers

Discord limits the amount of messages any user can send (you can try this yourself by spamming messages in any channel; you should see the same 5-second-interval behavior as your bot if you do it enough).

Sadly, the only solution for this is to send messages less often.

Related