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

230
Views
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 answers
Answer question

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 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!