Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda