Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion discord_http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ class MessageSnapshot:
"content",
"edited_timestamp",
"embeds",
"stickers",
"timestamp",
"type",
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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. """
Expand Down
33 changes: 16 additions & 17 deletions discord_http/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class PartialSticker(PartialBase):

__slots__ = (
"_state",
"format_type",
"guild_id",
"name",
"name"
)

def __init__(
Expand All @@ -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
Expand All @@ -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"<PartialSticker id={self.id}>"

Expand Down Expand Up @@ -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):
Expand All @@ -197,7 +208,6 @@ class Sticker(PartialSticker):
"_raw_type",
"available",
"description",
"format_type",
"pack_id",
"sort_value",
"tags",
Expand All @@ -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"]
Expand All @@ -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. """

Expand All @@ -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,
*,
Expand Down
Loading