Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda