Search code examples
javapermissionsdiscorddiscord4j

Mission Permission When Adding a Role to a Member Discord4J


In my program I try to add a role to a (new) member of a guild. But when I try to add the role to the member I get an error with the message: "Missing Permissions". What's confusing is that the bot already has permissions to manage roles. After I gave the bot admin rights but the error still came up.


Role studentRole = getRole(STUDENT_ROLE_NAME, tempMem.getGuild().block());
if(studentRole == null){
        tempMem.getPrivateChannel().block().createMessage("Sorry the Server doesn't have a \"Student\" Role contact admins for help!");
        return;
}
tempMem.addRole(studentRole.getId()).block();
tempMem.getPrivateChannel().block().createMessage("Successfully added you as a Student! Have fun :smile:");

Some further explaination to the code: Member tempMem: is the member which should recieve the student role. Role getRole(String name, Guild guild): is a method which just looks through the list of roles in a guild and returns the Role which has the right name given as a parameter. Every guild this bot is on should have a role with a name of STUDENT_ROLE_NAME. This snippet should just get the Student-role and assign it to the tempMem if everything works correctly.


Solution

  • As already said above i tried giving the bot "higher" permissions than the student role, but the solution was litteraly to move the role of the bot over the role of a student. So the missing permission error was actually correct