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

344
Vistas
Bad words filter is not working correctly discord.js v13

I was trying to make a bad words filter with my bot in discord.js v13 and node.js v16. I wrote a simple code but It's not working correctly.

My code:

const args = message.content.split(/ +/);
if ((message.guild.id = 'GUILD_ID')) {
  const bad = ['word1', 'word2'];
  if (bad.includes(args[0].join(' '))) {
    message.delete();
  } else {
    return;
  }
}

When I send a 'word1' message, It works correctly and deletes the message. but when I send for example: "Hello word1", It does not work.

What does It need to do?

  1. Delete the message if it includes a bad word.

Note: I am not getting any errors!

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

0

It's because you check if the array contains the string "Hello word1".

You can use Array#some() with a callback function to check if the string contains any of those words in the array:

function containsBadWords(str) {
  const badWords = ['word1', 'word2']

  if (badWords.some(word => str.toLowerCase().includes(word))) 
    return 'String contains bad words'
  else 
    return 'No bad words found'
}

console.log(containsBadWords('word1'))
console.log(containsBadWords('Some other text that includes word2 here'))
console.log(containsBadWords('No bad words here'))

// make sure you don't use single '=' here!
if (message.guild.id === 'GUILD_ID') {
  const bad = ['word1', 'word2']
  if (bad.some(word => message.content.includes(word)))
    message.delete()
  else
    return
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

array includes will not return true for your Hello world1 string. In your case you want to find if array includes that value by substring. This is not the way array.includes method works. Check out this answer In javascript, how do you search an array for a substring match

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