循环雪花阵列 [英] Loop through Snowflake array

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

问题描述

我正在寻找一种从此系列中获取数据的方法。

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:无法读取属性'user'为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,我认为你得到的东西是这样的(假设测试是你的公会对象):

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天全站免登陆