Source code for discohook.user

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

import aiohttp

from .asset import Asset
from .embed import Embed
from .file import File
from .params import _SendingPayload

    from .client import Client

[docs]class User: """ Represents a discord user. Properties ---------- id: :class:`str` The unique ID of the user. name: :class:`str` The name of the user. discriminator: :class:`str` The discriminator of the user. accent_color: Optional[:class:`int`] The accent color of the user. avatar: :class:`Asset` The avatar of the user. system: :class:`bool` Whether the user is a system user. bot: :class:`bool` Whether the user is a bot. mfa_enabled: :class:`bool` Whether the user has MFA enabled. locale: Optional[:class:`str`] The locale of the user. verified: :class:`bool` Whether the user is verified. email: Optional[:class:`str`] The email of the user. premium_type: Optional[:class:`int`] The premium type of the user. public_flags: Optional[:class:`int`] The public flags of the user. mention: :class:`str` Returns a string that allows you to mention the user. """ def __init__(self, client: "Client", data: Dict[str, Any]): = data self.client = client @property def id(self) -> str: return["id"] @property def name(self) -> str: return["username"] @property def global_name(self) -> Optional[str]: return"global_name") @property def discriminator(self) -> int: return int(["discriminator"]) @property def accent_color(self) -> Optional[int]: return"accent_color") @property def avatar(self) -> Asset: av_hash ="avatar") if av_hash: return Asset(hash=av_hash, fragment=f"avatars/{}") if self.discriminator == 0: av_hash = str((int( >> 22) % 6) else: av_hash = str(int(self.discriminator) % 5) return Asset(hash=av_hash, fragment="embed/avatars") @property def system(self) -> bool: return"system", False) @property def bot(self) -> bool: return"bot", False) @property def mfa_enabled(self) -> bool: return"mfa_enabled", False) @property def locale(self) -> Optional[str]: return"locale") @property def verified(self) -> bool: return"verified", False) @property def email(self) -> Optional[str]: return"email") @property def premium_type(self) -> Optional[int]: return"premium_type") @property def public_flags(self) -> Optional[int]: return"public_flags") def __str__(self) -> str: if self.discriminator == 0: return self.global_name or return f"{}#{self.discriminator}" def __eq__(self, other): return == @property def mention(self) -> str: return f"<@{}>"
[docs] async def send( self, content: str, *, tts: bool = False, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, file: Optional[File] = None, files: Optional[List[File]] = None, ) -> aiohttp.ClientResponse: """ Sends a message to the user. Parameters ---------- content: :class:`str` The content of the message. tts: :class:`bool` Whether the message should be sent using text-to-speech. embed: Optional[:class:`Embed`] The embed to be sent with the message. embeds: Optional[:class:`List`[:class:`Embed`]`] The embeds to be sent with the message. file: Optional[:class:`File`] The file to be sent with the message. files: Optional[:class:`List`[:class:`File`]`] The files to be sent with the message. """ payload = _SendingPayload( content=content, tts=tts, embed=embed, embeds=embeds, file=file, files=files, ) resp = await self.client.http.create_dm_channel({"recipient_id":}) data = await resp.json() channel_id = data["id"] return await self.client.http.send_message(channel_id, payload.to_form())