'How do I make a discord-bot stop replying after I write "shut up"?

I started on this small project just for fun for my friend's server. She wanted to have the bot reply to her any time she said anything in her server and she wanted the bot to stop replying after an hour after saying "shut up" (no prefixes). I currently have this

client.on("message", function (message) {
const amyID = "blahblah";
const jayID = "blahblah";
if (message.author.id == (jayID)) {
    if (message.content.includes("shut up")) {
        message.reply("sorry...")
        setTimeout(function () {

        }, 60000)
    } else {
        client.commands.get('replyToAmy').execute(message);
    }
  }
})

setTimeout seems to only work with functions which I am confused on how I can apply it to the client.on bit. If I remove setTimeout the bot will start responding again. How can I make the bot stop responding for a set amount of time after "shut up" is said by the user?



Solution 1:[1]

One way to do that would be create a boolean variable outside the client.on('message') function. Then the bot will keep sending a message as long as the boolean variable is set to true. Once the user tells the bot to stop, the boolean variable is set to false and you can create a .setTimeout() for the specified time after which the boolean variable will turn back to true. And then all we have to do is check if the boolean variable is true or not every time we send the message. The code might look something like this:

let keepReplying = true
const userId = 'the users id'
client.on('message', message => {
    if (message.author.id === userId) {
        if (message.content === 'stop') {
            keepReplying = false
            setTimeout(() => { keepReplying = true }, 60000)
        }
    }
    if (keepReplying) client.commands.get('replyToAmy').execute(message);
})

Solution 2:[2]

Maybe Create a list to contain the user who said shut up & timestamp then function to check user from that list and compare time with timestamp?

well if user timestamp > 1 hr then delete that from the list

there's a better way tho but this is the easy route. and not the most effective way as it would be too much waste with many users

but from your code seem like you just made small project for small group of users so there's no problem

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Caladan
Solution 2 HRN