首页 > 解决方案 > 如果玩家有角色(discord.js)

问题描述

所以我制作了一个不和谐的机器人,我想制作一个只有在使用该命令的人有一个名为“colorm”的角色时才有效的命令

这是这个代码

client.on('message', msg => {

  if (msg.content === '!setupcolors'){
    if(msg.guild.roles.find(role => role.name === "colorm")){
        console.log("cmd: !setupcolors >> Command used.");
        msg.reply(String('Hi! this command is under constuction'));
    }
    else{
        msg.reply(String('Hi! you need to have a rank called "colorm" to acces this command.'));
        console.log("Error[cmd: !setupcolors] >> No perms.");
    }
  }
});

谢谢!:D

标签: javascriptdiscord.jsroles

解决方案


尝试使用这个 -if(!msg.member.roles.cache.some(role => role.name === 'colorm'))


推荐阅读