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

165
Visualizações
Discord.js Cannot get member by ID on ready function

I have not used the latest Discord.js version 13 so I am quite unfamiliar with it.

I am trying to get a member by its ID on the client ready function.

client.guilds.cache.get("x").members.cache.get("x")

Members returns as undefined. This however works with members.fetch(), but I am not able to use this in my code.

But for some reason, this code works

 client.guilds.cache.forEach((guild) => {
     guild.members.cache.forEach((member) => {
       console.log(member)
     });
   });

Please help as I have tried this in the previous Discord.js v12 and it works perfectly fine.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

client.guilds.cache.get("x").members.cache.get("x") might not work due to either the guild or the member being uncached hence, unavialable to your client through cache you attemmpted to use member.fetch() as you said in your question although were unable to do so, maybe trying a wrong approach? let's try it right here!

client.once("ready", () => {
const guildId = 123456789012345678 // guild you want to fetch
const memberId = 123456789012345678 // member you want to fetch
client.guilds.fetch(`${guildId}`).then( (g) => { g.members.fetch(`${memberId}`) });
});

Easy stuff! feel free to comment if you face any other errors!

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