Skip to content

Conversation

AlexCai2019
Copy link

Add hasRole(Role) method to avoid creating an unmodified set before checking if a member has a role.

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

I believe the frequency of roles checking isn't low. Recently the getUnsortedRoles() method was introduced, and since you are working on roles, please reconsider adding hasRole() method to simplify role checking.
Usecase:

if (member.hasRole(guild.getRoleById(ADMIN_ROLE_ID)))
    asAdmin();
else
    asMember();

Add `hasRole(Role)` method to avoid creating an unmodified set before checking if a member has a role.
@MineKing9534
Copy link
Contributor

I think Member#hasRole(Long) would be more useful. Doing member.getUnsortedRoles().contains(...) isn't that bad, but member.getUnsortedRoles().stream().anyMatch(role -> role.getIdLong() == id) really is quite hard to read (Compared to member.hasRole(id)).
So I think the option to check for a role by id should also be added when adding a method for checking by role object.

(One might think about adding RoleSnowflake similar to UserSnowflake but that is probably overkill)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants