Browse Source

Add PartialEmoji.url_as

pull/6350/head
z03h 4 years ago
committed by Rapptz
parent
commit
fb9aa2486d
  1. 41
      discord/partial_emoji.py

41
discord/partial_emoji.py

@ -149,10 +149,43 @@ class PartialEmoji(_EmojiTag):
@property
def url(self):
""":class:`Asset`: Returns an asset of the emoji, if it is custom."""
""":class:`Asset`: Returns the asset of the emoji, if it is custom.
This is equivalent to calling :meth:`url_as` with
the default parameters (i.e. png/gif detection).
"""
return self.url_as(format=None)
def url_as(self, *, format=None, static_format="png"):
"""Returns an :class:`Asset` for the emoji's url, if it is custom.
The format must be one of 'webp', 'jpeg', 'jpg', 'png' or 'gif'.
'gif' is only valid for animated emojis.
.. versionadded:: 1.7
Parameters
-----------
format: Optional[:class:`str`]
The format to attempt to convert the emojis to.
If the format is ``None``, then it is automatically
detected as either 'gif' or static_format, depending on whether the
emoji is animated or not.
static_format: Optional[:class:`str`]
Format to attempt to convert only non-animated emoji's to.
Defaults to 'png'
Raises
-------
InvalidArgument
Bad image format passed to ``format`` or ``static_format``.
Returns
--------
:class:`Asset`
The resulting CDN asset.
"""
if self.is_unicode_emoji():
return Asset(self._state)
_format = 'gif' if self.animated else 'png'
url = "/emojis/{0.id}.{1}".format(self, _format)
return Asset(self._state, url)
return Asset._from_emoji(self._state, self, format=format, static_format=static_format)

Loading…
Cancel
Save