我已经做了一个转储命令,显示了所有在其中起作用的人的代码:
client.on("message", message => {
if(message.content == `+dump admin`) {
const ListEmbed = new MessageEmbed()
.setTitle('Users with the admin role:')
.setDescription(message.guild.roles.cache.get('741231292544188439').members.map(m=>m.user.tag).join('\n'));
message.channel.send(ListEmbed);
}
});
但是,仅对管理员角色显示。无论如何,它可能显示所提到的角色或角色名称。例如:
如果命令为+dump Owner
,则显示具有该角色的人员;如果命令+dump @Co-Owner
,则显示所有具有该角色的人员。意思是命令是否为+dump ${role}
,它显示所有具有该角色的人。预先谢谢你
答案 0 :(得分:0)
您可以创建一个args
变量,以使用String.prototype.slice()
,String.prototype.split()
和ES6
Spread Operator动态检查命令中发送的角色。这是一个命令片段演示:
const content = '+role Trial Moderator'
// slice(1) will slice the prefix off the beginning of the command
// split(/ +/) will split the content by every space and return an array
// we can then use array destructering and the spread operator to define both command and args
const [command, ...args] = content.slice(1).toLowerCase().split(/ +/);
console.log(command);
console.log(args);
// you could use this in a command handler:
if (command === 'something') {
// something function here
} else if (command === 'role') {
// we can also use the `args` variable to dynamically check message values
console.log(args.join(' '))
}
现在有了名称,您可以使用Collection.find()
来获取实际的角色对象。
if (command === 'role') {
// find a role by the same name
const role = message.guild.roles.cache.find(
(role) => role.name.toLowerCase() === args.join(' ')
);
if (!role)
return message.channel.send(
`Could not find a role by the name \`${args.join(' ')}\``
);
// make and send the embed dynamically
const ListEmbed = new MessageEmbed()
.setTitle(`Users with the \`${role.name}\` role:`)
.setDescription(role.members.map((m) => m.user.tag).join('\n'));
message.channel.send(ListEmbed);
}