javascript – 循环雪花阵列

我正在寻找一种从这个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:无法读取null的属性’user’

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

任何帮助都会有所帮助.

解决方法:

现在我查看了discord.js API,我认为你得到的东西是这样的(假设测试是你的公会对象):

test.members.forEach(function(guildMember, guildMemberId) {
   console.log(guildMemberId, guildMember.user.username);
})

如果这不起作用,请尝试以下方面:

var membersArray = test.members.array();

for(var guildMemberId in membersArray) {
   console.log(guildMemberId, membersArray[guildMemberId].user.username);
}
上一篇:Discord python on role grant event


下一篇:c#-BIDS和VS中的SSIS自定义控制任务调试UI