Skip to content

feat: add Member.has_any_role #1620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions interactions/models/discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,16 @@ def has_role(self, *roles: Union[Snowflake_Type, Role]) -> bool:
"""
return all(to_snowflake(role) in self._role_ids for role in roles)

def has_any_role(self, roles: List[Union[Snowflake_Type, Role]]) -> bool:
"""
Checks if the user has any of the given roles.

Args:
*roles: The Role(s) or role id(s) to check for

"""
return any((self.has_role(to_snowflake(role)) for role in roles))

async def timeout(
self,
communication_disabled_until: Union["Timestamp", datetime, int, float, str, None],
Expand Down
1 change: 1 addition & 0 deletions interactions/models/discord/user.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Member(FakeUserMixin):
async def remove_role(self, role: Union[Snowflake_Type, Role], reason: Absent[str] = ...) -> None: ...
async def remove_roles(self, roles: Iterable[Union[Snowflake_Type, Role]], reason: Absent[str] = ...) -> None: ...
def has_role(self, *roles: Union[Snowflake_Type, Role]) -> bool: ...
def has_any_role(self, roles: List[Union[Snowflake_Type, Role]]) -> bool: ...
async def timeout(
self,
communication_disabled_until: Union["Timestamp", datetime, int, float, str, None],
Expand Down