mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-21 00:07:51 +00:00
Add Member.get_role
Adds an efficient way to check if a member has a role by ID. This is done in a way consistent with the existing user API of the library. The more debated Member.has_role_id/has_role is intentionally not included for review at this time given the heavy bikeshedding of it.
This commit is contained in:
parent
1954861668
commit
1bf782fcb5
@ -830,3 +830,20 @@ class Member(discord.abc.Messageable, _BaseUser):
|
||||
user_id = self.id
|
||||
for role in roles:
|
||||
await req(guild_id, user_id, role.id, reason=reason)
|
||||
|
||||
def get_role(self, role_id: int) -> Optional[discord.Role]:
|
||||
"""Returns a role with the given ID from roles which the member has.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
role_id: :class:`int`
|
||||
The ID to search for.
|
||||
|
||||
Returns
|
||||
--------
|
||||
Optional[:class:`Role`]
|
||||
The role or ``None`` if not found in the member's roles.
|
||||
"""
|
||||
return self.guild.get_role(role_id) if self._roles.has(role_id) else None
|
||||
|
Loading…
x
Reference in New Issue
Block a user