循环遍历雪花数组 [英] Loop through Snowflake array

查看:22
本文介绍了循环遍历雪花数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从该集合中获取数据的方法.

I'm looking for a way to get data from this Collection.

数据如下:

  '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 }

我当前的循环是:

var user;
for(var u in test.members){
   user = test.members[u];
    console.log("["+u+"] "+user.username);
}

目前它会返回一个 TypeError: Cannot read property 'user' of null

我最初认为这个数据是一个数组,但它不是根据 Discord.js 文档,但我仍然不确定如何从集合中提取用户名数据.

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.

推荐答案

现在我查看了 discord.js API,我认为你要做的事情是这样的(假设 test 是你的公会对象):

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);
}

这篇关于循环遍历雪花数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆