Search code examples
node.jsdiscorddiscord.jsbots

Better method rather than setTimeout for mute command


So I have a Discord bot that does moderation and stuff. So I have timed the mute command and it removes the mute from the user when time ends. So I use setTimeout to query about the data from the database every second and if it finds that the expiry time is equal or is less than the current time it removes the mute. So is there any better option to do this? I am thinking this is increasing my bot's ram usage.


Solution

  • You could use a database for this. Let's get to the solution.

    Solution


    • Store the info in the database
      • When someone gets muted, store their data
      • You'll need to store their ID and the timestamp when the mute ends
    • Check the database every certain amount of time.
      • This can be achieved using setInterval()
      • Make some logic
        • Check if the mute has ended or not
        • If yes, remove the role. Otherwise, do nothing.