discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.26k stars 730 forks source link

Manage role didn't work and also not throw any error #2669

Closed sheiun closed 2 months ago

sheiun commented 3 months ago

General Troubleshooting

Version of JDA

v5.0.0-beta.23

Expected Behaviour

When we settings a bunch of roles inside a Discord server, the roles are ranked with level and when the BOT try to manage higher role, such as add higher role to a member, the API should throw some error to let me know this action is failed.

Code Example for Reproduction Steps

final Guild guild;  // my guild
final Role role; // a role in guild which is higher than bot's role
final Member member;  // a member in guild
guild.addRoleToMember(member, linkedRole).queue(
    success -> LOGGER.info("Role added successfully!"),
    failure -> LOGGER.error("Failed to add role: " + failure.getMessage()));

Code for JDABuilder or DefaultShardManagerBuilder used

JDA jda = JDABuilder.createDefault().build();

Exception or Error

Throw an error to failure callback

MinnDevelopment commented 3 months ago

The HierarchyException is thrown by addRoleToMember, before you even call queue. Are you sure that you properly handle exceptions being thrown?

sheiun commented 3 months ago

The HierarchyException is thrown by addRoleToMember, before you even call queue. Are you sure that you properly handle exceptions being thrown?

When I call the method guild.addRoleToMember it didn't throw any exception. And the bot did have the permission to manage the role but the roles higher than the bot's role will not work.

And no matter the bot's role is higher or lower than the target the method won't throw the exception.

MinnDevelopment commented 3 months ago

I just tried this again, and it definitely throws an exception:

net.dv8tion.jda.api.exceptions.HierarchyException: Can't modify a role with higher or equal highest role than yourself! Role: Role:highest role(id=280161492307804160)
    at net.dv8tion.jda.internal.entities.GuildImpl.checkPosition(GuildImpl.java:2031)
    at net.dv8tion.jda.internal.entities.GuildImpl.addRoleToMember(GuildImpl.java:1688)

Since you also called your variable linkedRole, it might refer to a managed role, in which case the request fails with a failure callback:

[pool-1-thread-11] ERROR RestAction - RestAction queue returned failure: [ErrorResponseException] 50013: Missing Permissions
net.dv8tion.jda.api.exceptions.ContextException
    at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54)
    at net.dv8tion.jda.api.requests.Request.<init>(Request.java:77)
    at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:203)
    at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:573)
    at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:539)

The same happens if for some reason the position check in JDA fails.

Please give me an easy to reproduce test-scenario, if you still encounter issues. Otherwise, I have to assume this issue is an incorrect handling of exceptions on your end.

MinnDevelopment commented 2 months ago

Closing due to inactivity.