diff options
| author | Nadir Chowdhury <[email protected]> | 2021-07-31 02:25:41 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-30 21:25:41 -0400 |
| commit | 60d82cf908e537e4ea5f068a31377452a9d6db3d (patch) | |
| tree | 9632e3e99759ad5818047a5132ca39afa30c0749 /discord/client.py | |
| parent | Fix user cache acting incorrectly with evictions (diff) | |
| download | discord.py-60d82cf908e537e4ea5f068a31377452a9d6db3d.tar.xz discord.py-60d82cf908e537e4ea5f068a31377452a9d6db3d.zip | |
implement guild stickers
Diffstat (limited to 'discord/client.py')
| -rw-r--r-- | discord/client.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py index 298dff3a..9c5c7dbf 100644 --- a/discord/client.py +++ b/discord/client.py @@ -60,6 +60,7 @@ from .appinfo import AppInfo from .ui.view import View from .stage_instance import StageInstance from .threads import Thread +from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory if TYPE_CHECKING: from .abc import SnowflakeTime, PrivateChannel, GuildChannel, Snowflake @@ -278,6 +279,14 @@ class Client: return self._connection.emojis @property + def stickers(self) -> List[GuildSticker]: + """List[:class:`GuildSticker`]: The stickers that the connected client has. + + .. versionadded:: 2.0 + """ + return self._connection.stickers + + @property def cached_messages(self) -> Sequence[Message]: """Sequence[:class:`.Message`]: Read-only list of messages the connected client has cached. @@ -777,6 +786,23 @@ class Client: """ return self._connection.get_emoji(id) + def get_sticker(self, id: int) -> Optional[GuildSticker]: + """Returns a guild sticker with the given ID. + + .. versionadded:: 2.0 + + .. note:: + + To retrieve standard stickers, use :meth:`.fetch_sticker`. + or :meth:`.fetch_nitro_sticker_packs`. + + Returns + -------- + Optional[:class:`.GuildSticker`] + The sticker or ``None`` if not found. + """ + return self._connection.get_sticker(id) + def get_all_channels(self) -> Generator[GuildChannel, None, None]: """A generator that retrieves every :class:`.abc.GuildChannel` the client can 'access'. @@ -1443,6 +1469,49 @@ class Client: data = await self.http.get_webhook(webhook_id) return Webhook.from_state(data, state=self._connection) + async def fetch_sticker(self, sticker_id: int) -> Union[StandardSticker, GuildSticker]: + """|coro| + + Retrieves a :class:`.Sticker` with the specified ID. + + .. versionadded:: 2.0 + + Raises + -------- + :exc:`.HTTPException` + Retrieving the sticker failed. + :exc:`.NotFound` + Invalid sticker ID. + + Returns + -------- + Union[:class:`.StandardSticker`, :class:`.GuildSticker`] + The sticker you requested. + """ + data = await self.http.get_sticker(sticker_id) + cls, _ = _sticker_factory(data['type']) # type: ignore + return cls(state=self._connection, data=data) # type: ignore + + async def fetch_nitro_sticker_packs(self) -> List[StickerPack]: + """|coro| + + Retrieves all available nitro sticker packs. + + .. versionadded:: 2.0 + + Raises + ------- + :exc:`.HTTPException` + Retrieving the sticker packs failed. + + Returns + --------- + List[:class:`.StickerPack`] + All available nitro sticker packs. + """ + data = await self.http.list_nitro_sticker_packs() + return [StickerPack(state=self._connection, data=pack) for pack in data['sticker_packs']] + async def create_dm(self, user: Snowflake) -> DMChannel: """|coro| |