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

229
Vistas
Discord.JS Customizable Banned Words/Filter

I'm trying to make a discord banned words filter that is customizable per server, similar to how MEE6, Dyno, etc does.

I currently have the server and the specified words saved in a database. What I have currently to filter these words is to query a database search in every single messages sent and I'm sure it is not a good idea.

example code :

client.on("messageCreate", async message => {
sql.query(`SELECT * FROM words WHERE serverid = ${serverID}`, (err, res) => {
  let words = res[0]
    for (let i in words) {
    if(message.content.includes(words[i])) return message.delete()
    }
  })
})

I thought that this method will be incredibly slow and inefficient when there is thousands of messages being sent simultaneously, I'm wondering if there is a better way to do this by storing the words in a cache/map or something, thanks.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I would run that query only when the bot starts up, and store them inside an object in client object so it could be accessed easily without having to rely on global object.

client.wordFilters = {}
// for every server id
sql.query(`SELECT * FROM words WHERE serverid = ${serverID}`, (err, res) => {
     client.wordFilters[serverID] = [...res] 
// assuming res is an array of banned words 
// or you need to turn it into an array first
// or just use it as an object, use it as how you see fit
  })

then every time a new banned word is added, don't forget to also push it to the array inside client.wordFilters[serverID]

client.on("messageCreate", async message => {
  // assuming the res object above is an array
  for (let i = 0; i < client.wordFilters[serverID]; i++){
     let word = client.wordFilters[serverID][i]
     if(message.content.includes(word)) return message.delete()
  }
})
about 4 years ago · Santiago Trujillo 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