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

349
Views
Discord.js: roles.some(r => !message.member.roles.cache.has(r)) doesn't work

So I am switching from single STAFF command (e.g. if(message.member.roles.cache.has(staff_id))) to more flexable method - if member has either helper or mod or admin role, etc. I used some method with array like this:

const roles = [
  "859471924753072188",
  "836214627243262002",
  "922170188089139261",
  "836214626923315221",
  "922170903394127873",
  "859878718599987200",
  "836214626617655296"
]
const isntStaff = roles.some(r => !message.member.roles.cache.has(r))

And now whenever I use this in some code, for example in this one:

...
if (
    rudeWords.some(word =>
      message
        .toString()
        .toLowerCase()
        .includes(word)
    ) &&
    isntStaff
  ) {
    message.delete({ reason: `Blacklisted Word Detected` });
    message.channel
      .send({ content: `${message.author}, do not use that word here, thank you.` })
      .then(msg => {
    setTimeout(() => msg.delete(), 3000)
  })

it just doesn't let me to use the word even if I have helper or mod or admin command. It also logs nothing in console.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There is also another way to do this according to this Discord.js Guide.

This is an example of how you could do this:

// Check if they have one of many roles
const roles = [
  "859471924753072188",
  "836214627243262002",
  "922170188089139261",
  "836214626923315221",
  "922170903394127873",
  "859878718599987200",
  "836214626617655296"
]

if (message.member.roles.cache.some(r => roles.includes(r.id)) ) {
  // has one of the roles
}else {
  // has none of the roles
}
about 4 years ago · Juan Pablo Isaza Report

0

Your code requires every single one of those roles. You are checking if there are any roles in that array that aren't in the member's role cache. Instead, put the ! on the outside

const roles = [
  "859471924753072188",
  "836214627243262002",
  "922170188089139261",
  "836214626923315221",
  "922170903394127873",
  "859878718599987200",
  "836214626617655296"
]
const isntStaff = !roles.some(r => message.member.roles.cache.has(r))
about 4 years ago · Juan Pablo Isaza 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!