diff --git a/discord_http/message.py b/discord_http/message.py index 3700e04..c59ba52 100644 --- a/discord_http/message.py +++ b/discord_http/message.py @@ -1510,6 +1510,7 @@ class MessageSnapshot: "content", "edited_timestamp", "embeds", + "stickers", "timestamp", "type", ) @@ -1540,6 +1541,9 @@ def __init__( self.attachments: list[Attachment] = [] """ The attachments of the message. """ + self.stickers: list[PartialSticker] = [] + """ The stickers of the message. """ + self._from_data(data) def _from_data(self, data: dict) -> None: @@ -1570,6 +1574,12 @@ def _from_data(self, data: dict) -> None: for a in message["attachments"] ] + if message.get("sticker_items", None): + self.stickers = [ + PartialSticker(state=self._state, id=int(s["id"]), name=s["name"], format_type=s["format_type"]) + for s in message["sticker_items"] + ] + class Message(PartialMessage): """ Represents a message object. """ @@ -1643,7 +1653,7 @@ def __init__( """ The attachments of the message. """ self.stickers: list[PartialSticker] = [ - PartialSticker(state=state, id=int(s["id"]), name=s["name"]) + PartialSticker(state=state, id=int(s["id"]), name=s["name"], format_type=s["format_type"]) for s in data.get("sticker_items", []) ] """ The stickers of the message. """ diff --git a/discord_http/sticker.py b/discord_http/sticker.py index ad40eed..75bd210 100644 --- a/discord_http/sticker.py +++ b/discord_http/sticker.py @@ -21,8 +21,9 @@ class PartialSticker(PartialBase): __slots__ = ( "_state", + "format_type", "guild_id", - "name", + "name" ) def __init__( @@ -31,7 +32,8 @@ def __init__( state: "DiscordAPI", id: int, # noqa: A002 name: str | None = None, - guild_id: int | None = None + guild_id: int | None = None, + format_type: int | None = 1 ): super().__init__(id=int(id)) self._state = state @@ -42,6 +44,9 @@ def __init__( self.guild_id: int | None = guild_id """ The ID of the guild this sticker is in, if any. """ + self.format_type: StickerFormatType = StickerFormatType(format_type) + """ The format type of the sticker. """ + def __repr__(self) -> str: return f"" @@ -187,7 +192,13 @@ async def delete( @property def url(self) -> str: """ Returns the sticker's URL. """ - return f"https://media.discordapp.net/stickers/{self.id}.png" + img_format = "png" + if self.format_type == StickerFormatType.gif: + img_format = "gif" + if self.format_type == StickerFormatType.lottie: + img_format = "json" + + return f"https://media.discordapp.net/stickers/{self.id}.{img_format}" class Sticker(PartialSticker): @@ -197,7 +208,6 @@ class Sticker(PartialSticker): "_raw_type", "available", "description", - "format_type", "pack_id", "sort_value", "tags", @@ -214,7 +224,8 @@ def __init__( state=state, id=int(data["id"]), name=data["name"], - guild_id=guild.id if guild else None + guild_id=guild.id if guild else None, + format_type=data["format_type"] ) self._raw_type: int = data["type"] @@ -225,9 +236,6 @@ def __init__( self.description: str = data["description"] """ The description of the sticker. """ - self.format_type: StickerFormatType = StickerFormatType(data["format_type"]) - """ The format type of the sticker. """ - self.pack_id: int | None = utils.get_int(data, "pack_id") """ The ID of the sticker pack this sticker belongs to, if any. """ @@ -251,15 +259,6 @@ def type(self) -> StickerType: """ The type of the sticker. """ return StickerType(self._raw_type) - @property - def url(self) -> str: - """ Returns the sticker's URL. """ - img_format = "png" - if self.format_type == StickerFormatType.gif: - img_format = "gif" - - return f"https://media.discordapp.net/stickers/{self.id}.{img_format}" - async def edit( self, *,