diff --git a/discord/asset.py b/discord/asset.py index ffb9d20af0..659d6dd5eb 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -274,6 +274,18 @@ def _from_cover_image(cls, state, object_id: int, cover_image_hash: str) -> Asse animated=False, ) + @classmethod + def _from_collectible( + cls, state: ConnectionState, asset: str, animated: bool = False + ) -> Asset: + name = "static.png" if not animated else "asset.webm" + return cls( + state, + url=f"{cls.BASE}/assets/collectibles/{asset}{name}", + key=asset, + animated=animated, + ) + @classmethod def _from_guild_image(cls, state, guild_id: int, image: str, path: str) -> Asset: animated = False diff --git a/discord/collectibles.py b/discord/collectibles.py index 0e8f2949ec..3eebac8401 100644 --- a/discord/collectibles.py +++ b/discord/collectibles.py @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. """ +from functools import cached_property from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -55,21 +56,15 @@ def __init__(self, data: NameplatePayload, state: "ConnectionState") -> None: def __repr__(self) -> str: return f"" - def get_asset(self, animated: bool = False) -> Asset: - """Returns the asset of the nameplate. - - Parameters - ---------- - animated: :class:`bool` - Whether to return the animated version of the asset, in webm version. Defaults to ``False``. - """ - fn = "static.png" if not animated else "asset.webm" - return Asset( - state=self._state, - url=f"{Asset.BASE}/assets/collectibles/{self._asset}{fn}", - key=self._asset.split("/")[-1], - animated=animated, - ) + @cached_property + def static_asset(self) -> Asset: + """The static :class:`Asset` of this nameplate.""" + return Asset._from_collectible(self._state, self._asset) + + @cached_property + def animated_asset(self) -> Asset: + """The animated :class:`Asset` of this nameplate.""" + return Asset._from_collectible(self._state, self._asset, animated=True) __all__ = ("Nameplate",)