Source code for discohook.member

from typing import TYPE_CHECKING, Any, Dict, List, Optional

from .asset import Asset
from .permission import Permission
from .role import PartialRole
from .user import User

    from .client import Client

[docs]class Member(User): """ Represents a member of a guild, subclassed from :class:`User`. """ def __init__(self, client: "Client", data: Dict[str, Any]): super().__init__(client, data) @property def guild_id(self) -> str: return["guild_id"] @property def nick(self) -> str: return"nick") or @property def roles(self) -> List[PartialRole]: ids ="roles") return [PartialRole(self.client, {"id": i, "guild_id": self.guild_id}) for i in ids] @property def joined_at(self) -> str: return["joined_at"] @property def premium_since(self) -> Optional[str]: return"premium_since") @property def permissions(self) -> int: return int("permissions", "0")) @property def pending(self) -> bool: return"pending", False) @property def disabled_until(self) -> Optional[str]: return"communication_disabled_until") @property def flags(self) -> int: return["flags"] @property def avatar(self) -> Asset: av_hash ="avatar") if not av_hash: return super().avatar return Asset(hash=av_hash, fragment=f"avatars/{}") @property def mention(self) -> str: """ Returns a string that allows you to mention the member. """ return f"<@!{}>" def has_permission(self, permission: Permission) -> bool: return Permission.check(self.permissions, permission)
[docs] async def add_role(self, role_id: str): """ Add a role to the member. Parameters ---------- role_id : str The ID of the role. """ return await self.client.http.add_role(self.guild_id,, role_id)
[docs] async def remove_role(self, role_id: str): """ Remove a role from the member. Parameters ---------- role_id : str The ID of the role. """ return await self.client.http.remove_role(self.guild_id,, role_id)
[docs] async def kick(self): """ Kick the member. """ return await self.client.http.kick_user(self.guild_id,
[docs] async def ban(self, *, delete_message_seconds: int = 0): """ Ban the member. Parameters ---------- delete_message_seconds: int The number of days to delete messages for. """ if delete_message_seconds > 604800: raise ValueError("You can only delete messages for up to last 7 days.") return await self.client.http.ban_user(self.guild_id,, delete_message_seconds)