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

228
Visualizações
discord.js return GuildMember undefined

I have a problem when I define "member" like that:

const guild = client.guilds.cache.get('my guild id')
const member = guild.members.cache.get('the member id that I need')

When I use it, I can't get its properties because the console tells me that it is undefined. So what's the problem?

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

0

First of all you need to make sure that you've enabled the GUILD_MEMBERS intent on the Discord developer portal in your application. After you've done that you need to include the intent in the Client.

const { Client, Intents } = require('discord.js');

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

After you've done this, it should work. If it doesn't work, the member isn't fetched or the user is not in the specified guild. If the member is in your server you need to fetch the user by using the fetch function. The fetch function will return a Promise which will return the GuildMember if the Promise is fullfilled. If the Promise is rejected, the member is not in your server or there was an error while trying to access the member. You can fetch the user in this way:

const { Client, Intents } = require('discord.js');

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

client.once('ready', async () => {
    var guild = client.guilds.cache.get('The Guild ID');
    if(!guild){
        try {
            guild = await client.guilds.fetch('The Guild ID');
        } catch (error) {
            return console.log(`Error while fetching the guild: `, error);
        }
    }
    var member = guild.members.cache.get('The User ID');
    if(!member){
        try {
            member = await guild.members.fetch(`The User ID`);
        } catch (error) {
            return console.log(`Error while fetching the member: `, error);
        }
    }
});

client.login('Your token');
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