简体   繁体   中英

showing user with multiple roles discord.js

with this command set to only one role. I want to set more than one role. how can I do it ?

let rolid = "663047983675342849"; 
  let tokuchi = client.guilds
    .get(sunucuid)
    .roles.get(rolid)
    .members.filter(o => !o.voiceChannel).map(member => member.user); 

 .setDescription(tokuchi.join("\n"))```

You can get all members with multiple role somethink like this, but other code shown leaves questions

    let sGuild = client.guilds.get(sunucuid)
    let membersWithRoles = sunucuid.members.filter(member => {
        return member.roles.some(r=>['ROLEID','ROLEID'].includes(r.id))
    })

console.log(membersWithRoles)

v2 version At the fist you dont need get guild in all comands, use message.guild for this.

This code will return array of users usernames with any of your roles and if they dont have voiceconnection now.

exports.run = async (client, message, args) => {
    if(message.channel.type === 'dm') return
    if (!message.member.hasPermission("ADMINISTRATOR"))
      return message.channel.send(" Missing Permission");
      let tokuchi = message.guild.members.filter(member => {
        return member.roles.some(r=>['ROLEID','ROLEID'].includes(r.id)) && !member.voiceChannel
    }).map(member => (member.user.username))

  const basarili = new Discord.RichEmbed()
      .setColor('RANDOM')
      .setAuthor(`Seste Olmayan Yetkililer`, client.user.avatarURL)
      .setDescription(tokuchi.join("\n"))
      .setFooter("Created by Tokuchi")
      .setTimestamp()
      .addField(`İşlemi Gerçekleştiren Kişi:`, `${message.author.username}#${message.author.discriminator}`)
  return message.channel.send(basarili)


  };

its return a users.username because you cant .join('\\n) users, its a collection, not array.

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