I would like my bot to delete a message by a user if it contains a certain word.
My bot work with node JS.
Thx for the help.
i tried to do a little code to delete the message, and it works but
the code delete the previous messages sent by the user
here is my code:
client.on("messageDelete", message => {
console.log(message)
if(message.content === "Bad word"){
message.delete
}
})
2
Answers
Store badWords inside array and then iterate through it and delete it.
Just in case you haven’t noticed (not say you haven’t), but you forgot to add () at the ".delete()" this is crucial for it to work. Apart from that the answer should work. Your code should look like this:
and not
Apart from this if you want you code to censor words that are lowercase and not just one word, but an array of words you can use the following code that I personally use myself.
For this to work you need to form an array of bad words to use, but you will figure it out. The code censors lower and upper string words, words with letters replaced with numbers and signs and also warns the offending user.