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

260
Views
DiscordJS cannot get _roles field after fetching member

I am fetching a member as:

//...
private user: GuildMember;
//...

try { 
    this.user = await interaction.guild?.members.fetch(SomeUserId)
}catch (e: unknown) {
    return await interaction.editReply("Couldn't find the specific user the in server.")
}

this.user will contain all the information regarding that specific user. It also includes a field _roles:['123456789', '123456789']. How can I get this specific field? Note that doing the following results in '_roles does not exist on type GuildMember':

console.log(this.user._roles)

Any way to access this field?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Found it!

...
private user: GuildMember | undefined; // Make sure to add undefined here too. Since .fetch returns a GuildMember or undefined
...

//To get that array use:
Array.from(this.user.roles.cache.keys())

//To get the Collection:
this.user.roles.cache.keys()

Leaving this here for that one random person that also has the same issue after 8 years.

about 4 years ago · Santiago Trujillo 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!