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

358
Visualizações
Get a List of Members in a Guild Discord.js

Can you list members of a guild you're not a part of with a Discord bot? I'm trying to grab guild members but it looks like:

  1. You can only add a bot to a discord server you have admin privileges in
  2. Your bot needs to be part of the "guild" (discord server) to access a member list

Number 2 is the one I'm uncertain of, some documentation seems to indicate that you can just add the guild's ID (which I grabbed via developer view) but the guild is returning "undefined" so I'm wondering if the problem is that number 2 is true but just not explicitly mentioned in any docs i could find.

I also thought of a workaround being to use my personal account that's already in the server's client id but I'm not sure I can set a client instance to my personal user ID.

If so how would I do that? I've already checked that my bot has privileged gateway intents enabled to grab members, but my client.guilds.cache.get("GUILD_ID"); is returning "undefined" (note that in my actual code this is the real guild ID).

Below is the full code, including configuration since I haven't seen anyone list that and I'm not even sure how the code is supposed to know what my clientID is meant to be

//Gets Discord API Wrapper
const discord = require("discord.js");
const fs = require('fs')
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

//This doesn't seem to actually do anything :/
client.on("ready", () => {
  console.log("I am ready!");
});

//GUILD_ID is my actual guild ID in live code
const list = client.guilds.cache.get("GUILD_ID"); 

console.log(list);

// Fetch and get the list named 'members'
list.members.each(member => {
  
  console.log(member.user.username)

  let content = member.displayName + "_" + member.user.id + "_" + member.user.nickname + "_" + member.user.username
      
      console.log(content)

      // Do whatever you want with the current member
      fs.writeFile('/memberinfo.txt', content, { flag: 'a+' }, err => {
        if (err) {
          console.error(err)
          return
        }
      })

}); 

//official docs include this after other code, but why after? TOKEN_VALUE is actual token in live code
client.login("TOKEN_VALUE");

I haven't even gotten past list.members.each(member => { so the code below is probably incorrect, but I just can't figure out why console.log(list); spits out "undefined" which is causing the following error:

TypeError: Cannot read properties of undefined (reading 'members')

Do I need to set clientId? How would I do that? What's the point of the token the bot generated if it's being set after the call is supposed to be made?

about 4 years ago · Juan Pablo Isaza
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