1
votes

I was watching a video on how to make a discord bot, and I did everything it said for me to do. and what the code does, is add a mute role and remove a role that lets you chat. and after the mute period, it removes the mute role and adds the role that lets you talk. This is my code and VS code shows no problems, so I don't think its a typo or Im missing a bracket:

    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

1 Answers

1
votes

I think the error is here: let muterole = message.guild.roles.cache.find(role => role.name == "muted ");. You need to remove the final space like: let muterole = message.guild.roles.cache.find(role => role.name == "muted ");

Because I think your role is named "muted" and not "muted ".