Add and remove a role, only one works
See original GitHub issueHello,
I’m really blocked since few day. Context : A member want validate a newbie. He write $validation @newbie_name and, after verification, I remove “newbie role” then add “Member role”.
Here is my method and the problem is identified by comment :
private void validation_membres(User user, MessageChannel channel, String[] arguments, Guild guild, Member demandeur) {
String joueurAvalider = "";
GuildController gc = new GuildController(guild);
for(int i = 0; i < arguments.length; i++) {
joueurAvalider += arguments[i] + " ";
}
Role role_membres = guild.getRolesByName("Membre", true).get(0);
Role role_newbies = guild.getRolesByName("newbies", true).get(0);
//if demandeur is member so he can validate a newbie
if(demandeur.getRoles().contains(role_membres)) {
//if joueur is a member of serveur
if(joueurAvalider.startsWith("@")) {
joueurAvalider = joueurAvalider.replace("@", "");
Member avalider = guild.getMembersByEffectiveName(joueurAvalider.trim(), false).get(0);
//if joueur is a newbie
if(avalider.getRoles().contains(role_newbies)) {
System.out.println("newbies oui");
//Validation running
//---------Here is the problem
gc.removeRolesFromMember(avalider, role_newbies).queue();
gc.addRolesToMember(avalider, role_membres).queue();
if(!avalider.getRoles().contains(role_newbies) && avalider.getRoles().contains(role_membres)) {
channel.sendMessage(":green_book: Joueur validé !").queue();
}
}
else { //player not a newbie
channel.sendMessage(":closed_book: Le joueur " + avalider.getEffectiveName() + " n'est pas un " + role_newbies.getName() + ". Il ne peut pas être validé.").queue();
}
}
else { //player unknown on server
channel.sendMessage(":closed_book: Le joueur à valider doit être tagué. Celà permet de vérifier qu'il est connu du serveur.").queue();
}
}
else { //demandeur not a member
channel.sendMessage(":closed_book: Uniquement les membres peuvent valider des joueurs.").queue();
}
}
I have permissions for this because when I do one by one, that works. With this code, role is add but no remove.
I’m lost. This morning, I’ve found this : Same problem
But if I do : guild.getManager(). I don’t have Add or remove …
Have you any ideas? Thank you
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Bot must add role and remove other, but it doesn't work
I have a command, that must remove other roles, after add one, but it's only remove. I know, that I need to resolve...
Read more >How To Add, Manage and Delete Roles in Discord - Alphr
1. Setting up your roles correctly is the key to managing your users on a Discord server. It's a good idea to have...
Read more >How to Assign and Remove Roles Automatically Based on ...
In this video, you will learn how to utilize the power of Statbot's Statroles to auto-assign roles to members in your Discord server...
Read more >Install or Uninstall Roles, Role Services, or Features
Remove roles, role services, and features by using Windows PowerShell cmdlets ... In a single session in the add Roles and Features Wizard, ......
Read more >Add / Remove a User's Role Association - Infoplus
From the list of roles on the right, click on the role you want to assign to the user. NOTE: You can only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well read my comment again edited it 👀 sorry
Consult the documentation of GuildController#addRolesToMember
There is a huge warning explaining your issue:
Warning
This may not be used together with any other role add/remove/modify methods for the same Member within one event listener cycle! The changes made by this require cache updates which are triggered by lifecycle events which are received later. This may only be called again once the specific Member has been updated by a GuildMemberRoleAddEvent. To add and remove Roles from a Member you should use
modifyMemberRoles(Member, Collection, Collection)