Removing and adding roles at the same time
Hello,
I am trying to remove certain roles and then add other roles to a member once a command is used.
The issue is that if you remove some roles and then add different roles, no roles will be removed from a member. This is an issue with asynchronous code. I have tried putting
addRole()
into a chained then()
but that does not solve the issue.
The only workaround I could find was using setTimeout()
which seems like a very wonky way to handle this.
Is there any other workaround I could use?14 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPuse this to add/remove the roles in one api request
I cannot use set for my use
why not?
Should have mentioned that in my post
please explain
Wouldn't setting the roles overwrite roles the member already has? I'd have to get the members roles and then use set with those and my changes. What if a role is above the bot's highest role? Will it just ignore that role or how is this handled?
yes, it sets the member's roles to what you provide in the array
I don't want to set all the member's roles though
I just want to add and remove some roles
so take the member's original roles, make an array, then add/remove the roles you want to add/remove, then pass the modified array to set()
My question remains
"What if a role is above the bot's highest role? Will it just ignore that role or how is this handled?"Would be annoying if the entire request would error without adding/removing any roles just because one of the roles the member already had is not accessible by the bot
i don't believe it'll throw an error but lemme see if i can get some clarification for you
Alright
Just tested that out and it seems to have worked
It does indeed just ignore roles the member already had before the set
So I just set the member's roles to their existing roles, filter out the roles that should be removed and add the new roles