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

321
Views
Trying to get how many members with specific role discord.js v12

I’m trying to count members of specific role but i’m getting error, message.guild.fetchMembers() is not a function

    let guild = await message.guild.fetchMembers();
    let roleID = '3933783737379';
    let memberCount = guild.roles.get(roleID).members.size;
    message.channel.send(memberCount + " members have this role!");
});

So if i just delete guild variable to make the code the code like this


let roleID = '3933783737379';
    let memberCount = message.guild.roles.get(roleID).members.size;
    message.channel.send(memberCount + " members have this role!");

He will count him self if he has it and count the owner only no one else counted

Is there any idea how to make this work?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

message.guild.fetchMember(); is not a thing in discord.js v12.

Discord.js v12 its message.guild.members.fetch();

Also members.fetch(); returns a GuildMemberCollection -> GuildMemberManager.fetch()
not a guild object. Just await the fetch function and it should work with your second code! :)

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!