本文介紹了循環遍歷雪花數組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在尋找一種從該集合中獲取數據的方法.
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);
}
這篇關于循環遍歷雪花數組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!