Javascript 如何检查用户是否具有特定角色discord.js v12?

Javascript 如何检查用户是否具有特定角色discord.js v12?,javascript,discord.js,Javascript,Discord.js,我刚刚开始创建我的discord机器人,我想发出一个警告命令,但我只希望具有版主角色的人能够使用它。有没有办法检查用户是否具有特定角色?谢谢到目前为止,我的代码是: module.exports = { name: 'warn', description: "The bot will warn the mentioned user", execute(message, args){ var warnedone = message.men

我刚刚开始创建我的discord机器人,我想发出一个警告命令,但我只希望具有版主角色的人能够使用它。有没有办法检查用户是否具有特定角色?谢谢到目前为止,我的代码是:

module.exports = {
    name: 'warn',
    description: "The bot will warn the mentioned user",
    execute(message, args){
        var warnedone = message.mentions.first()
        if(author doesnt have a role with ID 712229762742878321) {
             return message.reply('can not use this command')
        }
    }
}

如果要检查角色,可以执行以下操作:

if(!message.member.roles.cache.has('71222976742878321')){
返回消息.reply('无法使用此命令')
};
但是,我建议您检查权限,因为这会使该命令不适用于具有管理员角色的人。您可以像这样检查权限:

if(!message.member.permissions.has('MANAGE_ROLES')){
return message.reply(`您没有执行此命令所需的管理角色权限。`);
}
这样,所有拥有
管理角色
权限(通常为mods及以上)的人都可以使用该命令。 另外,我建议你改变一下

var warnedone=message.indications.first()

var warnedone=message.notices.members.first()
此外,如果您想通过ID向人们发出警告,您可以这样做:

var warnedone=message.indications.members.first()| | message.guild.members.cache.get(args[0]);

让我知道这是否有效:)

如果要检查角色,可以执行以下操作:

if(!message.member.roles.cache.has('71222976742878321')){
返回消息.reply('无法使用此命令')
};
但是,我建议您检查权限,因为这会使该命令不适用于具有管理员角色的人。您可以像这样检查权限:

if(!message.member.permissions.has('MANAGE_ROLES')){
return message.reply(`您没有执行此命令所需的管理角色权限。`);
}
这样,所有拥有
管理角色
权限(通常为mods及以上)的人都可以使用该命令。 另外,我建议你改变一下

var warnedone=message.indications.first()

var warnedone=message.notices.members.first()
此外,如果您想通过ID向人们发出警告,您可以这样做:

var warnedone=message.indications.members.first()| | message.guild.members.cache.get(args[0]);
让我知道这是否有效:)

给你

module.exports={
名称:“警告”,
description:“bot将警告提到的用户”,
执行(消息,参数){
var warnedone=message.indications.first()
if(!message.member.roles.cache.find(r=>r.id==“71222976742878321”)){
返回消息.reply('无法使用此命令')
}
}
}
给你

module.exports={
名称:“警告”,
description:“bot将警告提到的用户”,
执行(消息,参数){
var warnedone=message.indications.first()
if(!message.member.roles.cache.find(r=>r.id==“71222976742878321”)){
返回消息.reply('无法使用此命令')
}
}
}

更好的标志应该是
KICK\u成员
。更好的标志应该是
KICK\u成员