TheBrokennWorld
TheBrokennWorld

Reputation: 39

Issue with .addRole &.removeRole

I'm trying to create a mute command which will remove ALL your roles and add mute role, after a mute time it should return ALL your roles and take mute role. When I'm trying to take (or return) ALL roles it writes next:

(node:3720) UnhandledPromiseRejectionWarning: TypeError: Supplied parameter was neither a Role nor a Snowflake.

That takes the roles (and gives a muterole) after using mute command:

rmember.addRole(muterole.id) && rmember.removeRole(takenroles);

And that returns the roles (and takes a muterole) after mutetime expires:

rmember.removeRole(muterole.id) && rmember.addRole(takenroles) ;

That's how I'm trying to take roles:

let rmember = message.mentions.members.first()
let takenroles = rmember.roles

Upvotes: 0

Views: 94

Answers (1)

slothiful
slothiful

Reputation: 5623

GuildMember.addRole() and GuildMember.removeRole() only add/remove a single Role per call. To remove multiple at once, use GuildMember.addRoles() and GuildMember.removeRoles().

Promise.all([
  rmember.addRole(muterole),
  rmember.removeRoles(takenroles)
])
  .then(() => console.log('Muted.'))
  .catch(console.error);

Conversely...

Promise.all([
  rmember.removeRole(muterole),
  rmember.addRoles(takenroles)
])
  .then(() => console.log('Unmuted.'))
  .catch(console.error);

Upvotes: 1

Related Questions