mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Add support for get sticker pack
This commit is contained in:
parent
f9dbe60fc4
commit
34bf026a02
@ -2926,6 +2926,33 @@ class Client:
|
|||||||
data = await self.http.list_premium_sticker_packs()
|
data = await self.http.list_premium_sticker_packs()
|
||||||
return [StickerPack(state=self._connection, data=pack) for pack in data['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:
|
async def create_dm(self, user: Snowflake) -> DMChannel:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
@ -1609,6 +1609,9 @@ class HTTPClient:
|
|||||||
def get_sticker(self, sticker_id: Snowflake) -> Response[sticker.Sticker]:
|
def get_sticker(self, sticker_id: Snowflake) -> Response[sticker.Sticker]:
|
||||||
return self.request(Route('GET', '/stickers/{sticker_id}', sticker_id=sticker_id))
|
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]:
|
def list_premium_sticker_packs(self) -> Response[sticker.ListPremiumStickerPacks]:
|
||||||
return self.request(Route('GET', '/sticker-packs'))
|
return self.request(Route('GET', '/sticker-packs'))
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ import unicodedata
|
|||||||
|
|
||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
from .asset import Asset, AssetMixin
|
from .asset import Asset, AssetMixin
|
||||||
from .utils import cached_slot_property, find, snowflake_time, get, MISSING, _get_as_snowflake
|
from .utils import cached_slot_property, snowflake_time, get, MISSING, _get_as_snowflake
|
||||||
from .errors import InvalidData
|
|
||||||
from .enums import StickerType, StickerFormatType, try_enum
|
from .enums import StickerType, StickerFormatType, try_enum
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -51,7 +50,6 @@ if TYPE_CHECKING:
|
|||||||
Sticker as StickerPayload,
|
Sticker as StickerPayload,
|
||||||
StandardSticker as StandardStickerPayload,
|
StandardSticker as StandardStickerPayload,
|
||||||
GuildSticker as GuildStickerPayload,
|
GuildSticker as GuildStickerPayload,
|
||||||
ListPremiumStickerPacks as ListPremiumStickerPacksPayload,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -353,9 +351,12 @@ class StandardSticker(Sticker):
|
|||||||
|
|
||||||
Retrieves the sticker pack that this sticker belongs to.
|
Retrieves the sticker pack that this sticker belongs to.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.5
|
||||||
|
Now raises ``NotFound`` instead of ``InvalidData``.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
--------
|
--------
|
||||||
InvalidData
|
NotFound
|
||||||
The corresponding sticker pack was not found.
|
The corresponding sticker pack was not found.
|
||||||
HTTPException
|
HTTPException
|
||||||
Retrieving the sticker pack failed.
|
Retrieving the sticker pack failed.
|
||||||
@ -365,13 +366,8 @@ class StandardSticker(Sticker):
|
|||||||
:class:`StickerPack`
|
:class:`StickerPack`
|
||||||
The retrieved sticker pack.
|
The retrieved sticker pack.
|
||||||
"""
|
"""
|
||||||
data: ListPremiumStickerPacksPayload = await self._state.http.list_premium_sticker_packs()
|
data = await self._state.http.get_sticker_pack(self.pack_id)
|
||||||
packs = data['sticker_packs']
|
return StickerPack(state=self._state, data=data)
|
||||||
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}')
|
|
||||||
|
|
||||||
|
|
||||||
class GuildSticker(Sticker):
|
class GuildSticker(Sticker):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user