2 javascript node.js discord.js
我的代码是
const list = client.guilds.find("id", "335507048017952771")
for (user of list.users){
console.log(user[1].username);
}
Run Code Online (Sandbox Code Playgroud)
这实际上没有任何作用。没有错误或任何东西。
我只是想让机器人找到一个服务器,然后从该服务器记录所有成员。
显示所有连接的用户 Discord.js这个问题的答案根本没有帮助我。我确实尝试使用,message.guild.users但也没有任何作用。在 Discord.js 网站上似乎也找不到任何可以帮助我的东西。
首先,不要使用.find("id", "335507048017952771"),你应该使用.get("335507048017952771"),正如它在 discord.js文档中所说的那样。
Discord.js 中使用的所有集合都使用它们的 id 属性映射,如果你想通过 id 查找,你应该使用 get 方法。有关详细信息,请参阅MDN。
一个公会没有users财产,在那里,因为它有一个members属性,它返回一个集合的GuildMember秒。现在username要从每个成员那里获取 ,您可以从userGuildMember的属性中获取。因此,您需要遍历 GuildMembers 的集合,并获取<GuildMember>.user.username.
有几种方法可以做到这一点,我将使用该forEach()方法。结果如下:
// Get the Guild and store it under the variable "list"
const list = client.guilds.get("335507048017952771");
// Iterate through the collection of GuildMembers from the Guild getting the username property of each member
list.members.forEach(member => console.log(member.user.username));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38677 次 |
| 最近记录: |