Loop through Snowflake array
Solution 1
Now i looked into the discord.js API and i think what u got todo is something like this (assuming test is your guild object):
test.members.forEach(function(guildMember, guildMemberId) {
console.log(guildMemberId, guildMember.user.username);
})
If that doesn't work try along the lines of:
var membersArray = test.members.array();
for(var guildMemberId in membersArray) {
console.log(guildMemberId, membersArray[guildMemberId].user.username);
}
Solution 2
TypeError: Cannot read property 'user' of null
means your user
variable is null which means test.members[u]
is null.
Try logging the test.members
first and see if its filled.
user.user.username
is probably wrong. As it looks it should be just user.username
Carl
Updated on June 08, 2022Comments
-
Carl about 2 years
I'm looking for a way to get data from this Collection.
The data looks like:
'0000000' => GuildMember { guild: Guild { members: [Object], id: '000000', name: 'Zombie', _rawVoiceStates: [Object] }, user: User { id: '0000000', username: 'Orc', _roles: [ '0000' ], nickname: 'Orc', joinedTimestamp: 00000, lastMessageID: null }, '0000000' => GuildMember { guild: Guild { members: [Object], id: '000000', name: 'Zombie', _rawVoiceStates: [Object] }, user: User { id: '0000001', username: 'Orc1', _roles: [ '0000' ], nickname: 'Orc', joinedTimestamp: 00000, lastMessageID: null }, _array: null, _keyArray: null }
My current loop is:
var user; for(var u in test.members){ user = test.members[u]; console.log("["+u+"] "+user.username); }
It currently kicks back a
TypeError: Cannot read property 'user' of null
I originally thought this the data was an array, but it's not according to the Discord.js docs, but I'm still not sure how to pull the username data from the collection.
Any help would be helpful.