Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!