vikrant
vikrant

Reputation: 118

how to get all members id in discord.js

i am trying to a make a list of all the members id of a given guild id. I am trying various things but all are giving collections. how can i only retrieve the ids.

console.log(msg.guild.name)
console.log(msg.guild.id)
console.log(msg.guild.members.fetch());

the log is

 '690958932406960249' => GuildMember {
 guild: [Guild],
 user: [User],
 joinedTimestamp: 1586525303612,
 lastMessageID: null,
 lastMessageChannelID: null,
 premiumSinceTimestamp: null,
 deleted: false,
 _roles: []
 },
'690988332653608980' => GuildMember {
guild: [Guild],
user: [User],
joinedTimestamp: 1591198472051,
lastMessageID: null,
lastMessageChannelID: null,
premiumSinceTimestamp: null,
deleted: false,
 _roles: []
 },

Upvotes: 1

Views: 1232

Answers (2)

Jakye
Jakye

Reputation: 6625

You can map the members' IDs using Array.prototype.map(). Example:

const Members = client.guilds.cache.get("GuildID").members.map(member => member.id);
// Returns Array: ["4634643643262345", "684369346943609235", "4683496834643653543"] etc...

Upvotes: 1

yonder
yonder

Reputation: 45

From the collection, you can use .keys() method to get the keys (ID of the members).

let memberIds = Array.from(collection.keys())

Upvotes: 0

Related Questions