Skip to content
Advertisement

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.

JavaScript

Btw, the code is in discord.js!

Advertisement

Answer

Your problem is this chunk of code

JavaScript

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

JavaScript

If they react with a 👎 add them to the set.

JavaScript

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

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement