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

117
Views
Get all users with specific role using discord.js

I'm getting RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined. with this code. Can someone help me with what's undefined here?

I'm using discord.js v13.6.0.

require('dotenv').config();
const token = process.env.bot_token;

const { Client, Intents } = require("discord.js")
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.NON_PRIVILEGED,
    Intents.GUILD_MEMBERS
  ]
});

const prefix = '!getUserByRole';

client.on("messageCreate", (message) =>{
    if(!message.content.startsWith(prefix) || message.author.bot || message.author.id) return;
    const args = message.content.slice(prefix.length).split(/ +/);
    const roleId = args[1];
    message.guild.members.fetch().then((members)=>{
        members.filter(mmbr => mmbr.roles.cache.get(roleId)).map(m => {
            console.log(m.user.tag, m.user.id);
        });
    })
})

client.login(token);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In discord.js v13 Intents.ALL, Intents.NON_PRIVILEGED, and Intents.PRIVILEGED have all been removed to discourage bad practices. It means you need to remove Intents.NON_PRIVILEGED.

Also, there is no Intents.GUILD_MEMBERS, it should be Intents.FLAGS.GUILD_MEMBERS. So you'll need to update your code like this:

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_MEMBERS,
  ],
});
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!