notratz
notratz

Reputation: 25

"TypeError: person.removeRole is not a function"

I am trying to create a timed mute bot for my discord server, but then it says "Person.removeRole is not a function"
Is there any fix for this?

bot.on('message', message => {
  let args = message.content.substring(PREFIX.length).split(" ");

  switch (args[0]) {
    case 'mute':
      var person = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[1]));
      if (!person) return message.reply("I can't find the user noob ");

      let mainrole = message.guild.roles.cache.find(role => role.name === "Epic Members");
      let role = message.guild.roles.cache.find(role => role.name === "mute");


      if (!role) return message.reply(" can't find the mute role noob, Create a mute role named 'mute'.")


      let time = args[2];
      if (!time) {
        return message.reply("Put a dman time u noob");
      }

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


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

      setTimeout(function() {

        person.addRole(mainrole.id)
        person.removeRole(role.id);
        console.log(role.id)
        message.channel.send(`@${person.user.tag} has been unmuted noob`)
      }, ms(time));
      break;
  }
});

Upvotes: 0

Views: 934

Answers (2)

Milo Moisson
Milo Moisson

Reputation: 124

Check you work with discord.js V12 and use:

person.roles.remove(roleResolvable)
person.roles.add(roleResolvable)

Also check: Discord.js: Role Manager -> add

(A role resolvable can be a role object or an id)

Upvotes: 2

Federico Grandi
Federico Grandi

Reputation: 6806

The .addRole() and .removeRole() methods only exist in the GuildMember class in v11 (docs): if you're using discord.js@v12 you'll need to use the GuildMember.roles property:

person.roles.remove(mainrole)
person.roles.add(role)

Upvotes: 1

Related Questions