@@ -507,7 +507,9 @@ def get_avatar_url(
507507 url += ".gif" if self .avatar .startswith ("a_" ) else ".png"
508508 return url
509509
510- async def get_guild_permissions (self , guild : "Guild" ) -> Permissions :
510+ async def get_guild_permissions (
511+ self , guild_id : Optional [Union [int , Snowflake , "Guild" ]] = MISSING
512+ ) -> Permissions :
511513 """
512514 Returns the permissions of the member for the specified guild.
513515
@@ -521,6 +523,18 @@ async def get_guild_permissions(self, guild: "Guild") -> Permissions:
521523 :return: Base permissions of the member in the specified guild
522524 :rtype: Permissions
523525 """
526+ from .guild import Guild
527+
528+ if guild_id is MISSING :
529+ _guild_id = self .guild_id
530+ if isinstance (_guild_id , LibraryException ):
531+ raise _guild_id
532+
533+ else :
534+ _guild_id = int (guild_id ) if not isinstance (guild_id , Guild ) else int (guild_id .id )
535+
536+ guild = Guild (** await self ._client .get_guild (int (_guild_id )), _client = self ._client )
537+
524538 if int (guild .owner_id ) == int (self .id ):
525539 return Permissions .ALL
526540
@@ -531,7 +545,49 @@ async def get_guild_permissions(self, guild: "Guild") -> Permissions:
531545 role = await guild .get_role (role_id )
532546 permissions |= int (role .permissions )
533547
534- if permissions & Permissions .ADMINISTRATOR == Permissions . ADMINISTRATOR :
548+ if Permissions .ADMINISTRATOR in Permissions ( permissions ) :
535549 return Permissions .ALL
536550
537551 return Permissions (permissions )
552+
553+ async def has_permissions (
554+ self ,
555+ * permissions : Union [int , Permissions ],
556+ channel : Optional [Channel ] = MISSING ,
557+ guild_id : Optional [Union [int , Snowflake , "Guild" ]] = MISSING ,
558+ operator : str = "and" ,
559+ ) -> bool :
560+ """
561+ Returns whether the member has the permissions passed.
562+
563+ .. note::
564+ If the channel argument is present, the function will look if the member has the permissions in the specified channel.
565+ If the argument is missing, then it will only consider the member's guild permissions.
566+
567+ :param *permissions: The list of permissions
568+ :type *permissions: Union[int, Permissions]
569+ :param channel: The channel where to check for permissions
570+ :type channel: Channel
571+ :param guild_id: The id of the guild
572+ :type guild_id: Optional[Union[int, Snowflake, Guild]]
573+ :param operator: The operator to use to calculate permissions. Possible values: `and`, `or`. Defaults to `and`.
574+ :type operator: str
575+ :return: Whether the member has the permissions
576+ :rtype: bool
577+ """
578+ perms = (
579+ await self .get_guild_permissions (guild_id )
580+ if channel is MISSING
581+ else await channel .get_permissions_for (self )
582+ )
583+
584+ if operator == "and" :
585+ for perm in permissions :
586+ if perm not in perms :
587+ return False
588+ return True
589+ else :
590+ for perm in permissions :
591+ if perm in perms :
592+ return True
593+ return False
0 commit comments