Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

javascript - Discord.js memberlist with the specified role command

I have this memberlist command which works but if I will say a role that is not created on the server it will not send the if(!rrole) quote it will send the embed for mention the id, and also if I will try to run the command with an existing role it will not send anything and will give me an error which says Cannot read property 'id' of undefined

module.exports = {
    name: 'memberlist',
    description: 'shows the member list with the specified role',
    async execute(message, args, Discord) {
        const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[0])
        const embe = new Discord.MessageEmbed()
        .setDescription(`${message.author.username} Mention the role or put the role ID`)
        .setColor("RANDOM")
        .setTimestamp()
      if(!role) return message.channel.send(embe); 
        const rid = message.content.split(' ').splice(1).join(' ');
        const rrole = message.guild.roles.cache.find(val => val.id === rid);
        if (!rrole) return message.channel.send({embed: {description: `${message.author.username} `${rid}` 
is not a role on this server`, 
color: "RANDOM", timestamp: new Date()}});
        const members = await message.guild.members.fetch().then((member) => {
            if (Array.isArray(member)) {
              return member(
                (m) =>
                `? **${m.displayName}**
                      (${m.user.tag} - ${member.user.id})`
              )
            } else {
              return `? **${member.displayName}**
                           (${member.user} - ${member.user.id})`
            }
          })
        if(!members)
        return message.channel.send({embed: {description: 
`there are no members that currently have **${role.name}** role`, color: "RANDOM", timestamp: new Date()}});
        const embed = new Discord.MessageEmbed()
        .setColor("RANDOM")
        .addField({
            name: `List of ${members}`,
            value: `${message.guild.roles.cache.get(role).members.map(m=> "? " + 
`${m.user.username}` + "#" + m.user.discriminator + `
(${m.user.id})`).join('
')}
            that have the role `${role.name}``,
            description: members,
            maxPerPage: 20,
            page: Number(message.arg),
        });
        message.channel.send(embed)
    }
}
question from:https://stackoverflow.com/questions/65945024/discord-js-memberlist-with-the-specified-role-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...