简体   繁体   English

Discord.JS | 显示具有特定角色的用户

[英]Discord.JS | Display Users who have a specific roles

My name is Tana or Hellen.我的名字是塔娜或海伦。 So am trying to make when a user has a specific role to add him to the embed like this example bot?因此,我试图在用户具有特定角色时将他添加到嵌入中,就像这个示例机器人一样? What should I do or could you help me with the code?我应该怎么做,或者你能帮我写代码吗? Thanks so much!!非常感谢!!

在此处输入图像描述

If I am reading this correctly, you want it to only have users that have a specific role?如果我没看错,你希望它只有具有特定角色的用户吗? Well, here you go.好吧,这里是 go。

client.on("message", msg => {
//<property> can be replaced with role id, to find by id, with role name, to find by name, etc.
var allUsers = [];
msg.guild.members.fetch(); //cache users
msg.guild.members.cache.forEach(m => {
 if(m.roles.cache.find(r => r.<property> === "whatever")) allUsers.push(m);
})
})

With this, the array allUsers will end up having all the users with the role you chose.这样,数组allUsers最终将拥有您选择的角色的所有用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM