DiscordJS - Fetch Multiple Users at Once

Viewed 354

Instead if fetching every user by itself, I am trying to fetch an array of users at once.

This is the code I am trying to use:

var idsArr= ['682999909523259483','234269235071811584','503303866016727050'];
  
    
const membersArr = await interaction.guild.members.fetch({
    idsArr,
});
    
console.log(membersArr);

Even though I only give it an array of 3 IDs, it logs every member of the server. Any suggestion on how to fix that?

1 Answers

I just searched through official discord.js examples, and found this:

// Fetch by an array of users including their presences
guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true })
  .then(console.log)
  .catch(console.error);

Maybe you should do this instead:

var idsArr= ['682999909523259483','234269235071811584','503303866016727050'];
  
    
const membersArr = await interaction.guild.members.fetch({
    user: idsArr,
});
    
console.log(membersArr);

(Notice field name user instead of idsArr)

Related