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

192
Views
Discord.js Get the member in a guild by username

I was trying to get all the member's usernames on my discord server
However, it just gave back 8-9/25 members including 6 BOTs

Here is my code

const list = client.guilds.cache.get(msg.guildId); 
list.members.cache.each(r => {
   console.log(r.user.username)
})

Besides that, I have also tried these ways

const list = client.guilds.cache.get(msg.guildId); 
   list.members.cache.array().forEach(r => {
      console.log(r.user.username)
})
const user = client.users.cache.find(u => u.username == '//The Given username')
const user = msg.guild.roles.cache.get('//The Main Role in my Server')
             .members.map(m => m.user.username == '//The given username')
let user = client.users.cache.get('username', '//The given username');

But sometimes it just returned my and my BOT's username or undefined.

I'm trying to get all the members on the server and from that, I can find out the user has the same username with the given username, not tags or IDs

I have turned on the Gateway Intents but it didn't help

Please help with my project, I really need all the suggestions from you

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

0

Use .fetch() to cache all members, and return them. Make sure you have GUILD_MEMBERS intent:

list.members.fetch().then(m => {
  let members = m.map(u => u.user.username)
  console.log(members) //array of all members
  //you can also use "m.each(u => console.log(u.user.username))" to log each one individually
})

Or use async-await

const m = await list.members.fetch()
let members = m.map(u => u.user.username)
console.log(members)
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!