Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
Discord js profanity filter does send double message after 2 words detected in one message

Is there a way to stop this ? If it checks the database for words for example (ARE,DOING) If a message has been send like this: (how are you doing) it triggers 2x delete message and 2x my message.

this is how i have it setup:

Database12.find(guild, async(err, data) => {
        splittedMsgs.map((content) =>{
             if(message.content.bot) return
            if (data.Words.includes(content.toLowerCase())){
                
                //deletes the bad message
                message.delete()
                // reply a message when a bad word has been detected
                message.reply(replies[random])
                .then(msg => {
                let time = "5s";
          setTimeout(function () {
           // if (message.author.bot) return;
         //deletes the detected message
            msg.delete();
            
          }, ms(time));
            })
                .catch(console.log("error"));
            };
        });
    
    });

I did try a lot, but i don't find a way to stop it looping when 2 words are detected at the same time in one message.

regards

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could consider using Array.some. That way, it will stop looping through the array, if a given element resolves to true:


Database12.find(guild, async (err, data) => {
    if (message.content.bot) return
    if (splittedMsgs.some((content) => data.Words.includes(content.toLowerCase()))) {
        //deletes the bad message
        message.delete()
        // reply a message when a bad word has been detected
        message.reply(replies[random])
            .then(msg => {
                let time = "5s";
                setTimeout(function () {
                    // if (message.author.bot) return;
                    //deletes the detected message
                    msg.delete();

                }, ms(time));
            })
            .catch(console.log("error"));
    }
});

Besides, you should always use the correct array method. You used Array.map, which is typically used to create a new array whilst changing each element of the given array see here. If you just want to iterate over each element (without changing it), you should use Array.forEach instead see here.

If you are interested, here is an article with a short explanation and examples regarding some array methods.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda