Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda