如何在discord.js中获取所有成员ID

时间:2020-07-10 16:38:54

标签: javascript discord.js

我正在尝试列出给定公会ID的所有成员ID。我正在尝试各种东西,但是所有人都在收藏。我怎么只能检索ID。

console.log(msg.guild.name)
console.log(msg.guild.id)
console.log(msg.guild.members.fetch());

日志是

 '690958932406960249' => GuildMember {
 guild: [Guild],
 user: [User],
 joinedTimestamp: 1586525303612,
 lastMessageID: null,
 lastMessageChannelID: null,
 premiumSinceTimestamp: null,
 deleted: false,
 _roles: []
 },
'690988332653608980' => GuildMember {
guild: [Guild],
user: [User],
joinedTimestamp: 1591198472051,
lastMessageID: null,
lastMessageChannelID: null,
premiumSinceTimestamp: null,
deleted: false,
 _roles: []
 },

2 个答案:

答案 0 :(得分:1)

您可以使用Array.prototype.map()映射成员的ID。 示例:

const Members = client.guilds.cache.get("GuildID").members.map(member => member.id);
// Returns Array: ["4634643643262345", "684369346943609235", "4683496834643653543"] etc...

答案 1 :(得分:0)

您可以从集合中使用.keys()方法来获取密钥(成员的ID)。

let memberIds = Array.from(collection.keys())