Browse Source

Add support for get sticker pack

pull/9932/head
Andrin 7 months ago
committed by GitHub
parent
commit
34bf026a02
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      discord/client.py
  2. 3
      discord/http.py
  3. 18
      discord/sticker.py

27
discord/client.py

@ -2926,6 +2926,33 @@ class Client:
data = await self.http.list_premium_sticker_packs()
return [StickerPack(state=self._connection, data=pack) for pack in data['sticker_packs']]
async def fetch_premium_sticker_pack(self, sticker_pack_id: int, /) -> StickerPack:
"""|coro|
Retrieves a premium sticker pack with the specified ID.
.. versionadded:: 2.5
Parameters
----------
sticker_pack_id: :class:`int`
The sticker pack's ID to fetch from.
Raises
-------
NotFound
A sticker pack with this ID does not exist.
HTTPException
Retrieving the sticker pack failed.
Returns
-------
:class:`.StickerPack`
The retrieved premium sticker pack.
"""
data = await self.http.get_sticker_pack(sticker_pack_id)
return StickerPack(state=self._connection, data=data)
async def create_dm(self, user: Snowflake) -> DMChannel:
"""|coro|

3
discord/http.py

@ -1609,6 +1609,9 @@ class HTTPClient:
def get_sticker(self, sticker_id: Snowflake) -> Response[sticker.Sticker]:
return self.request(Route('GET', '/stickers/{sticker_id}', sticker_id=sticker_id))
def get_sticker_pack(self, sticker_pack_id: Snowflake) -> Response[sticker.StickerPack]:
return self.request(Route('GET', '/sticker-packs/{sticker_pack_id}', sticker_pack_id=sticker_pack_id))
def list_premium_sticker_packs(self) -> Response[sticker.ListPremiumStickerPacks]:
return self.request(Route('GET', '/sticker-packs'))

18
discord/sticker.py

@ -28,8 +28,7 @@ import unicodedata
from .mixins import Hashable
from .asset import Asset, AssetMixin
from .utils import cached_slot_property, find, snowflake_time, get, MISSING, _get_as_snowflake
from .errors import InvalidData
from .utils import cached_slot_property, snowflake_time, get, MISSING, _get_as_snowflake
from .enums import StickerType, StickerFormatType, try_enum
__all__ = (
@ -51,7 +50,6 @@ if TYPE_CHECKING:
Sticker as StickerPayload,
StandardSticker as StandardStickerPayload,
GuildSticker as GuildStickerPayload,
ListPremiumStickerPacks as ListPremiumStickerPacksPayload,
)
@ -353,9 +351,12 @@ class StandardSticker(Sticker):
Retrieves the sticker pack that this sticker belongs to.
.. versionchanged:: 2.5
Now raises ``NotFound`` instead of ``InvalidData``.
Raises
--------
InvalidData
NotFound
The corresponding sticker pack was not found.
HTTPException
Retrieving the sticker pack failed.
@ -365,13 +366,8 @@ class StandardSticker(Sticker):
:class:`StickerPack`
The retrieved sticker pack.
"""
data: ListPremiumStickerPacksPayload = await self._state.http.list_premium_sticker_packs()
packs = data['sticker_packs']
pack = find(lambda d: int(d['id']) == self.pack_id, packs)
if pack:
return StickerPack(state=self._state, data=pack)
raise InvalidData(f'Could not find corresponding sticker pack for {self!r}')
data = await self._state.http.get_sticker_pack(self.pack_id)
return StickerPack(state=self._state, data=data)
class GuildSticker(Sticker):

Loading…
Cancel
Save