[英]How do I get specific values from a collection map
所以我在這里嘗試使用 DiscordJS 制作一個機器人。 我目前正在嘗試顯示用戶詳細信息。 當我獲得詳細信息時,我不確定如何獲取特定詳細信息。
所以我通過這樣做來獲得用戶
const user = await utils.findUser(message, args[0]);
現在在這里,我根據用戶在 args 中輸入的任何內容來獲取用戶。 用戶變量看起來像這樣:
Collection [Map] {
'211975876747853825' => GuildMember {
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
shardID: 0,
name: 'Elchea Kingdom',
icon: 'cd8156aed6c8ebc482df2252936afcee',
splash: null,
region: 'eu-west',
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: null,
verificationLevel: 'MEDIUM',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
defaultMessageNotifications: 'MENTIONS',
systemChannelFlags: [SystemChannelFlags],
vanityURLCode: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
ownerID: '211975876747853825',
emojis: [GuildEmojiManager]
},
user: User {
bot: false,
discriminator: '0006',
avatar: '5ebd62928be9bd413a2b5f6e638587ea',
lastMessageID: null,
lastMessageChannelID: null,
flags: [UserFlags]
},
premiumSinceTimestamp: null,
deleted: false,
_roles: [
'600421802702929920',
'600737807664939008',
'603343858549391360',
'600425094598361091',
'600422841279578118',
'603314411243044875',
'617699524474830859',
'603316305495326740',
'617505016328224790',
'617449137767710743'
]
}
}
現在假設我想獲得公會名稱“Elchea Kingdom”。 我怎么能那樣做? 我曾嘗試使用 Map.prototype.values() 並對其進行迭代,但它不起作用。 我得到一個未定義的值。 我試過做一些愚蠢的事情,比如 user[0] 和 user.Guild 來獲取公會信息。 但我總是不斷得到未定義的價值。 我做錯了什么,請您指導我。
https://discord.js.org/#/docs/main/stable/class/Collection
您應該調用變量 users 然后通過.first()
獲取成員
const users = await utils.findUser(message, args[0]);
const member = users.first();
const user = member.user;
順便說一句,您將哪個庫用於變量utils
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.