0

So I'm trying to get all the user IDs in my discord server. I am able to pull in a Collection Map however I'm not familiar with them so I would really appreciate it if someone could explain how I'm suppose to get everyone's IDs using this collection map. I really appreciate your help thanks!

Here is my code

const Discord = require('discord.js');
const bot = new Discord.Client();

const token = 'HIDDEN';

bot.on('ready', () => {
    const list = bot.guilds.cache.get("HIDDEN"); 
    console.log(list.members);

})

bot.login(token);

1 Answer 1

1

You need to use Guild.members.cache to get a Collection of members. You can then use Array.prototype.map() (which works on Collections too) to map the users by their ID.

Example:

const Guild = bot.guilds.cache.get("GuildId")
const Members = Guild.members.cache.map(member => member.id);
console.log(Members)
// --> ['UserId', 'UserId', 'UserId', 'UserId', 'UserId','UserId' 'UserId' etc...]
1
  • 10/10 Thanks so much!
    – RAT
    Commented Jul 26, 2020 at 19:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.