Reputation: 35
I'm trying to get a random winner for prizes and I would like to take the whole object variable and just sorta isolate the whole thing so i just get a list of the UserID's
Heres an example of what I get when I do console.log(message.guild.members.fetch())
:
Promise {
Collection [Map] {
'123456789012345678' => GuildMember {
guild: [Guild],
user: [User],
joinedTimestamp: 1234567890123,
lastMessageID: '012345678901234567',
lastMessageChannelID: '012345678901234567',
deleted: false,
_roles: [Array]
},
'234567890123456789' => GuildMember {
guild: [Guild],
user: [User],
joinedTimestamp: 1234567890123,
lastMessageID: null,
lastMessageChannelID: null,
premiumSinceTimestamp: null,
deleted: false,
_roles: [Array]
},
'345678901234567890' => GuildMember {
guild: [Guild],
user: [ClientUser],
joinedTimestamp: 1234567890123,
lastMessageChannelID: null,
premiumSinceTimestamp: null,
deleted: false,
_roles: [Array]
}
}
}
I would like to only get the 123456789012345678
part of the '123456789012345678' => GuildMember {
line
Upvotes: 1
Views: 2422
Reputation: 14088
Use the keys
method (inherited from Map
):
message.guild.messages.fetch().then(members => {
const userIDs = [...members.keys()]
// Do something with the IDs here
})
With async/await:
const userIDs = [...(await message.guild.messages.fetch()).keys()]
// Do something with the IDs here
Upvotes: 2