Discord Bot无法找到角色

时间:2020-04-01 09:55:00

标签: javascript bots discord discord.js

我正在观看有关如何制作不和谐机器人的视频,并且做了我说过的所有事情。代码的作用是添加一个静音角色并删除一个可以聊天的角色。在静音期过后,它将删除静音角色,并添加可让您讲话的角色。这是我的代码,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;

1 个答案:

答案 0 :(得分: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 "