Reputation: 118
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
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
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