Add hasAnyPermission(Permission... permissions) method to IPermissionHolder #3045
lajczik
started this conversation in
Feedback & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, checking whether a permission holder has at least one of several permissions requires chaining multiple
hasPermissioncalls with||, e.g.This is verbose and inefficient because each call recomputes the effective permissions. Adding a dedicated
hasAnyPermissionmethod would simplify the code and allow for potential internal optimizations (e.g., computing permissions once and checking all bits).Motivation
hasPermission(which requires all permissions) and theCollectionoverloads.Proposed API
Add the following methods to the
IPermissionHolderinterface:Additionally, provide default convenience overloads for
Collection<Permission>:Implementation considerations
hasPermissionmethods are implemented inMemberandRole(likely viaPermissionUtil). The new methods would follow a similar pattern, usingPermissionUtil.checkAnyPermissionor a variant.getEffectivePermission(for guild) andgetEffectivePermission(channel, holder)to obtain the permission bits once, then check(effective & raw) != 0for each required permission.trueat the first match, allowing early exit.Example usage
Related discussion
This feature has been requested informally by the community (e.g., [link to any existing discussions if known]), and it aligns with similar utilities in other libraries.
Beta Was this translation helpful? Give feedback.
All reactions