Skip to content

Commit

Permalink
Use new endpoint for StandardSticker.pack()
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofandrin committed Aug 7, 2024
1 parent 9f24fd7 commit d868662
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions discord/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

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__ = (
Expand All @@ -51,7 +50,6 @@
Sticker as StickerPayload,
StandardSticker as StandardStickerPayload,
GuildSticker as GuildStickerPayload,
ListPremiumStickerPacks as ListPremiumStickerPacksPayload,
)


Expand Down Expand Up @@ -352,9 +350,12 @@ async def pack(self) -> StickerPack:
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.
Expand All @@ -364,13 +365,8 @@ async def pack(self) -> StickerPack:
: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):
Expand Down

0 comments on commit d868662

Please sign in to comment.