Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Profanity list detection Discord.js V12

I have an image command for my bot. This is used for memes and other funny pictures. My bot just scrapes Google for the best result. But on the other side, you can also look up, well, NSWF images. Since I don't want people sending those, I am trying to build a profanity filter. It now works like this:

$image cheese 

If the word cheese is chosen, nothing should happen, but if there is something NSWF, the bot should detect that and delete the $image NSFW-word command. I already have a list of profanity list, now just the implementation. My command now, that doesn't work is:

    const blacklist = require("./../Other/profanity.js");

    blacklist.forEach((word) => {
      if (message.content.toLowerCase().includes(word));
      message.delete();
      message.channel.send("Let's try to keep it family friendly!");
      console.log(`${message.author} used the word ${word} in an image search.`)
    }); 

My profanity list (profanity.js) looks like this:

module.exports = [
"NSFW1",
"NSFW2",
"NSWF3",
"Etc"
]

Also, I should note, that piece of code is broken. Even if someone sends cheese, it spams (infinite times, untill I shut-down the bot) the 'lets-keep-it-family-friendly' phrase. I searched the whole internet, but couldn't find the right fit.

So can anyone help me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It doesn't work because you have a mistake in the "if" part (if something end). And actually the "if" doesn't work and it executes the next functions for each word in the array.

Maybe something like this:

blacklist.forEach(word => {
    if (message.content.toLowerCase().includes(word.toLowerCase())){
        message.delete();
        message.channel.send("Let's try to keep it family friendly!");
        console.log(`${message.author} used the word ${word} in an image search.`)

        return; // stop forEach
    }
});

You can also use includes() method to check if the word is in the string array blacklist.includes(word). Note that it will look for exact same string so it might not be useful in this case.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!