Discord Bot无法找到角色

问题描述 投票:1回答:1

我正在观看有关如何制作不和谐机器人的视频,我做了我说过的所有事情。代码的作用是添加一个静音角色并删除一个允许您聊天的角色。在静音期过后,它将删除静音角色,并添加可让您讲话的角色。这是我的代码,VS代码没有问题,所以我认为它没有错字或缺少括号:

    case 'mute':
    let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
    if(!person) return message.reply("User Doesn't Exist");

    let mainrole = message.guild.roles.cache.find(role => role.name == "normal");
    let muterole = message.guild.roles.cache.find(role => role.name == "muted ");

    if(!muterole) return message.reply("Role Doesn't Exist");

    let time = args[2];

    if(!time){
        return message.reply("How Long?");
    }

    person.removeRole(mainrole.id);
    person.addRole(muterole.id);

    message.channel.send(`@${person.user.tag} has now been muted for ${ms(ms(time))}`);

    setTimeout(function(){
        person.addRole(mainrole.id);
        person.removeRole(muterole.id);
        message.channel.send(`@${person.user.tag} has now been unmuted`)
    }, ms(time));
    break;
javascript bots discord discord.js
1个回答
1
投票

我认为错误在这里:let muterole = message.guild.roles.cache.find(role => role.name == "muted ");。您需要删除最后的空格,例如:let muterole = message.guild.roles.cache.find(role => role.name == "muted ");

因为我认为您的角色名为"muted",而不是"muted "

热门问题
推荐问题
最新问题