Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda