Fetch or get information out of a collection


Fetch or get information out of a collection

I'm working with Discord API and node.js. In a Discord server we can assign members to specific "roles". "Members" are one of them, "admin" is another. In this case we are working with a custom one, not that it matters. When I'm fetching every member of a certain role on the Discord server the API returns a collection looking something like this:

RoleMembers = { userID:{user}, userID:{user}, userID:{user}, userID:{user} }

The problem is that without knowing the keywords (userID) I cannot fetch any data in the {user} object. I've tried treating it like an array and loop through an index, but it just returns undefined.

I have no clue on how to treat this data that the API is feeding me.

The API documentation tells me this is what is returned:

.members READ-ONLY The cached guild members that have this role Type: Collection<Snowflake, GuildMember> 

Tried with this loop, but it isn't giving me anything.:

var roles = message.channel.guild.roles; var roleMembers = roles.get(settings.ptID).members; for (var member in roleMembers) { var jsonMember = { ID:member.id, Name:member.nickname } obj.Members.push(member); } 

Is there any way for me to either transform the collection into an indexed array? Or to fetch the keywords so that I can make a loop to fetch the data I need in the user object? I'm honestly not even sure what a "collection" mean in this context, or how to make operations on it.

Submitted August 14, 2017 at 01:37AM by Etaro
via reddit http://ift.tt/2uDeXfL

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s