简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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