我如何让我的不和谐机器人列出某个角色的人?

时间:2020-07-28 15:27:22

标签: javascript bots discord.js

我试图使discord.js机器人列出具有特定角色的人员,但是我不知道如何使它起作用。我想要做的是列出具有特定角色的人员,并每2分钟(或类似时间)刷新一次嵌入内容。现在,我收到一个错误消息,说ReferenceError: message is not defined

if (message.member.roles.cache.has('732362918854787103')) {
    const embed = new Discord.MessageEmbed()
      .setTitle(`List of Muted People`)
      .setColor('#0099ff')
      .setDescription(`List of people who are muted.`)
    const support = client.channels.cache.get('732360387101589596')
    if (support) support.send(embed);
};

1 个答案:

答案 0 :(得分:1)

以下代码应为您提供所需的结果:

// Get the role by its name
var yourRole = message.guild.roles.cache.find(role => role.name == "your role");
// Get all members that have the role
var members = message.guild.members.cache.filter(member => member.roles.cache.find(role => role == yourRole)).map(member => member.user.tag);
// Send message containing the members that were found (this can be implemented however you want)
message.channel.send(members);