warburp warburp - 2 years ago 147
Javascript Question

grabbing all of one value type from a collection

I'm working on a Discord.js bot trying to add roles to mentioned users in a command. it stores all of the mention data for the message in a collection msg.mentions.users and looks something like this.

'189920214777856000' => User {
id: '189920214777856000',
username: 'Warburp',
discriminator: '2542',
avatar: 'e83b4777a8abfd7f4cfc0f04761520b4',
bot: false,
status: 'online',
game: null } }

What Id would like to do is collect all of the id's that were mentioned into an array so I can use a for loop too add them all to a role. Distinct is not recognized when I try to use it and find required I add a value and only finds exactly what I specify.

Answer Source

Collection.keyArray() is possibly what you're looking for. From what I understand msg.mentions.users is a Collection object mapping IDs to User objects. So something like this will give you an array of the user IDs:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download