How do I delete a user’s new message

I’m pretty trash at coding so I need a little bit of help. I’m trying to code my discord bot to delete someone’s messages for one minute after they click a react emoji. It sounds simple but for my tiny pea brain, it’s not. This is what I have got so far. It deletes all messages from different users and guilds it’s in, forever. I want it so it only delete messages in one channel for one minute.

  client.once('message', async userMessage => {
    if (userMessage.content.startsWith('')) 
         botMessage = await'Who here likes goats?')
            await botMessage.react("๐Ÿ‘") 
            await botMessage.react("๐Ÿ‘Ž") 
        const filter = (reaction, user) => {
                return (
                  ["๐Ÿ‘", "๐Ÿ‘Ž"].includes( && ===
              .awaitReactions(filter, { max: 1, time: 60000, errors: ["time"] })
              .then((collected) => {
                const reaction = collected.first();
                if ( === "๐Ÿ‘Ž") {
      `${}, how dare you. I guess no on here likes me. Hmmm, because of that I shall now eat all your messages! BAAAAAHAHAHHAHAHA!`)
                setTimeout(() => {
                  client.on("message", async msg => {
                    if (author.msg.content.startsWith("")) {
               = await msg.delete();
                }, 2000);
                } else {
              .catch((_collected) => {

Btw, the code is in discord.js!


Your problem is this chunk of code

setTimeout(() => {
   client.on("message", async msg => {
      if (author.msg.content.startsWith("")) { = await msg.delete();
}, 2000);

This is not how you use events.

A) Your message event is nested within another which could cause memory leaks.

B) To get the content you need to use msg.content, author.msg Is not a thing.

C) I assume your intention here: msg.content.startsWith("") is to always fire the if statement, in that case why not do if (true).

Here’s how I would do it:

Create a Set in the namespace which will hold id’s of users who’s messages should be deleted

const toDelete = new Set();

If they react with a ๐Ÿ‘Ž add them to the set.

if ( === "๐Ÿ‘Ž") {'Your message here');

   if (!toDelete.has( {

On each message event check if the author of the message has their id in the set, If so delete their message

client.once('message', async userMessage => {
    if (toDelete.has( {
       return userMessage.delete()

    if (userMessage.content.startsWith('')) {
       // Rest of your code