如何检查特定不和谐服务器中有多少人扮演角色?

时间:2020-08-22 15:58:56

标签: javascript discord discord.js

我想看看我的服务器中有多少人具有Helper角色。

到目前为止,我的代码:

client.on('message', message =>{
  let server = "746326753466908742"
  var yourRole = message.guild.roles.cache.find(role => role.name == "Helper");
  var members = message.guild.members.cache.filter(member => member.roles.cache.find(role => role == yourRole)).map(member => member.user.tag);
  let sunucuTanıtım = new Discord.MessageEmbed()
  .setTitle('IECode Sunucu:')
  .setDescription(`Helperları Aşşağıdaki Listeden Görebilirsiniz.\n\Sunucudaki Helper Listesi: ${members}`)
  .setFooter(`${message.author.tag}`, message.author.displayAvatarURL())

if (message.content === `${prefix}server`)
message.channel.send(sunucuTanıtım)
})

1 个答案:

答案 0 :(得分:1)

Role具有一个名为members的属性,即Collection。因此,您可以使用:

console.log(Role.members.cache.size)
// --> 50 (depending on how many people have the role)