stuff

Criado O diff nunca expira
268 remoções
526 linhas
147 adições
404 linhas
diff --git a/discord/client.py b/discord/client.py
diff --git a/disnake/client.py b/disnake/client.py
--- a/discord/client.py
--- a/disnake/client.py
+++ b/discord/client.py
+++ b/disnake/client.py
-from .emoji import Emoji
-from .emoji import Emoji
+from .emoji import AppEmoji, GuildEmoji
+from .emoji import ApplicationEmoji, GuildEmoji
+ cache_app_emojis: :class:`bool`
+ cache_app_emojis: bool = False,
+ Whether to automatically fetch and cache the application's emojis on startup and when fetching. Defaults to ``False``.
+ cache_app_emojis=cache_app_emojis,
+
+ cache_app_emojis: bool,
+ .. warning::
+ cache_app_emojis=cache_app_emojis,
+
- def emojis(self) -> List[Emoji]:
+ There are no events related to application emojis - if any are created/deleted on the
- """List[:class:`.Emoji`]: The emojis that the connected client has."""
+ Developer Dashboard while the client is running, the cache will not be updated until you manually
+ def emojis(self) -> List[Union[GuildEmoji, ApplicationEmoji]]:
+ run :func:`fetch_emojis`.
+
+ .. versionadded:: 2.7
- def emojis(self) -> list[Emoji]:
- """The emojis that the connected client has."""
+ def emojis(self) -> list[GuildEmoji | AppEmoji]:
+ """The emojis that the connected client has.
+ """The emojis that the connected client has.
+
+
+ .. note::
+ .. note::
+
+ This only includes the application's emojis if :attr:`~Client.cache_app_emojis` is
+ This only includes the application's emojis if :attr:`~Client.cache_app_emojis` is ``True``.
+ ``True``.
+ """
+ """
- def get_emoji(self, id: int, /) -> Emoji | None:
- def get_emoji(self, id: int, /) -> Optional[Emoji]:
+ def get_emoji(self, id: int, /) -> GuildEmoji | AppEmoji | None:
+ def get_emoji(self, id: int, /) -> Optional[Union[GuildEmoji, ApplicationEmoji]]:
- Optional[:class:`.Emoji`]
+ Optional[:class:`.GuildEmoji` | :class:`.AppEmoji`]
+
+
+ async def fetch_emojis(self) -> list[AppEmoji]:
+ async def fetch_application_emojis(self) -> list[ApplicationEmoji]:
+ r"""|coro|
+ r"""|coro|
+
+ Retrieves all custom :class:`ApplicationEmoji`\s from the application.
+ Retrieves all custom :class:`AppEmoji`\s from the application.
+
+
+ Raises
+ Raises
+ ---------
+ ------
+ HTTPException
+ HTTPException
+ An error occurred fetching the emojis.
+ An error occurred fetching the emojis.
+
+
+ Returns
+ Returns
+ --------
+ -------
+ List[:class:`AppEmoji`]
+ List[:class:`ApplicationEmoji`]
+ The retrieved emojis.
+ The retrieved emojis.
+ """
+ """
+ data = await self._state.http.get_all_application_emojis(self.application_id)
+ data = await self._connection.http.get_all_application_emojis(self.application_id)
+ return [
+ return [
+ self._state.maybe_store_app_emoji(self.application_id, d)
+ self._connection.store_application_emoji(self.application_id, d) for d in data["items"]
+ for d in data["items"]
+ ]
+ ]
+
+
+ async def fetch_emoji(self, emoji_id: int, /) -> AppEmoji:
+ async def fetch_application_emoji(self, emoji_id: int, /) -> ApplicationEmoji:
+ """|coro|
+ """|coro|
+
+ Retrieves a custom :class:`ApplicationEmoji` from the application.
+ Retrieves a custom :class:`AppEmoji` from the application.
+
+
+ Parameters
+ Parameters
+ ----------
+ ----------
+ emoji_id: :class:`int`
+ emoji_id: :class:`int`
+ The emoji's ID.
+ The emoji's ID.
+
+
+ Returns
+ Returns
+ -------
+ -------
+ :class:`AppEmoji`
+ :class:`ApplicationEmoji`
+ The retrieved emoji.
+ The retrieved emoji.
+
+
+ Raises
+ Raises
+ ------
+ ------
+ NotFound
+ NotFound
+ The emoji requested could not be found.
+ The emoji requested could not be found.
+ HTTPException
+ HTTPException
+ An error occurred fetching the emoji.
+ An error occurred fetching the emoji.
+ """
+ """
+ data = await self._state.http.get_application_emoji(
+ data = await self._connection.http.get_application_emoji(self.application_id, emoji_id)
+ self.application_id, emoji_id
+ return self._connection.store_application_emoji(self.application_id, data)
+ )
+ return self._state.maybe_store_app_emoji(self.application_id, data)
+
+
+ async def create_emoji(
+ async def create_application_emoji(
+ self,
+ self,
+ *,
+ *,
+ name: str,
+ name: str,
+ image: bytes,
+ image: bytes,
+ ) -> AppEmoji:
+ ) -> ApplicationEmoji:
+ r"""|coro|
+ r"""|coro|
+
+ Creates a custom :class:`ApplicationEmoji` for the application.
+ Creates a custom :class:`AppEmoji` for the application.
+
+ There is currently a limit of 2000 emojis per application.
+ There is currently a limit of 2000 emojis per application.
+
+
+ Parameters
+ Parameters
+ -----------
+ ----------
+ name: :class:`str`
+ name: :class:`str`
+ The emoji name. Must be at least 2 characters.
+ The emoji name. Must be at least 2 characters.
+ image: :class:`bytes`
+ image: :class:`bytes`
+ The :term:`py:bytes-like object` representing the image data to use.
+ The :term:`py:bytes-like object` representing the image data to use.
+ Only JPG, PNG and GIF images are supported.
+ Only JPG, PNG and GIF images are supported.
+
+
+ Raises
+ Raises
+ -------
+ ------
+ Forbidden
+ Forbidden
+ You are not allowed to create emojis.
+ You are not allowed to create emojis.
+ HTTPException
+ HTTPException
+ An error occurred creating an emoji.
+ An error occurred creating an emoji.
+
+
+ Returns
+ Returns
+ --------
+ -------
+ :class:`AppEmoji`
+ :class:`ApplicationEmoji`
+ The created emoji.
+ The created emoji.
+ """
+ """
+
+ img = utils._bytes_to_base64_data(image)
+ img = utils._bytes_to_base64_data(image)
+ data = await self._state.http.create_application_emoji(
+ data = await self._connection.http.create_application_emoji(self.application_id, name, img)
+ self.application_id, name, img
+ return self._connection.store_application_emoji(self.application_id, data)
+ )
diff --git a/disnake/emoji.py b/disnake/emoji.py
+ return self._state.maybe_store_app_emoji(self.application_id, data)
--- a/disnake/emoji.py
+
+++ b/disnake/emoji.py
+ async def delete_emoji(
-from typing import TYPE_CHECKING, Any, Iterator, List, Optional, Tuple, Union
+ self, emoji: Snowflake, *, reason: str | None = None
+from typing import TYPE_CHECKING, Any, Iterator, List, Optional, Tuple
+ ) -> None:
+ """|coro|
+
+ Deletes the custom :class:`AppEmoji` from the application.
+
+ Parameters
+ ----------
+ emoji: :class:`abc.Snowflake`
+ The emoji you are deleting.
+
+ Raises
+ ------
+ HTTPException
+ An error occurred deleting the emoji.
+ """
+
+ await self._state.http.delete_application_emoji(self.application_id, emoji.id)
+ if self._state.cache_app_emojis and self._state.get_emoji(emoji.id):
+ self._state.remove_emoji(emoji)
diff --git a/discord/emoji.py b/discord/emoji.py
--- a/discord/emoji.py
+++ b/discord/emoji.py
-__all__ = ("Emoji",)
-__all__ = ("Emoji",)
+__all__ = (
+__all__ = ("Emoji", "GuildEmoji", "ApplicationEmoji")
+ "Emoji",
- from .guild_preview import GuildPreview
+ "GuildEmoji",
+ "AppEmoji",
+)
-class Emoji(_EmojiTag, AssetMixin):
-class Emoji(_EmojiTag, AssetMixin):
- """Represents a custom emoji.
-
- Depending on the way this object was created, some attributes can
- have a value of ``None``.
-
- .. container:: operations
-
- .. describe:: x == y
-
- Checks if two emoji are the same.
-
- .. describe:: x != y
-
- Checks if two emoji are not the same.
-
- .. describe:: hash(x)
-
- Return the emoji's hash.
-
- .. describe:: iter(x)
-
- Returns an iterator of ``(field, value)`` pairs. This allows this class
- to be used as an iterable in list/dict/etc constructions.
-
- .. describe:: str(x)
-
- Returns the emoji rendered for discord.
-
- Attributes
- ----------
- name: :class:`str`
- The name of the emoji.
- id: :class:`int`
- The emoji's ID.
- require_colons: :class:`bool`
- If colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
- animated: :class:`bool`
- Whether an emoji is animated or not.
- managed: :class:`bool`
- If this emoji is managed by a Twitch integration.
- guild_id: :class:`int`
- The guild ID the emoji belongs to.
- available: :class:`bool`
- Whether the emoji is available for use.
- user: Optional[:class:`User`]
- The user that created the emoji. This can only be retrieved using :meth:`Guild.fetch_emoji` and
- having the :attr:`~Permissions.manage_emojis` permission.
- """
+class BaseEmoji(_EmojiTag, AssetMixin):
+class BaseEmoji(_EmojiTag, AssetMixin):
+ "application_id",
+ "application_id",
- def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload):
- def __init__(
- self, *, guild: Union[Guild, GuildPreview], state: ConnectionState, data: EmojiPayload
- ) -> None:
- self.guild_id: int = guild.id
- self.guild_id: int = guild.id
+ def __init__(self, *, state: ConnectionState, data: EmojiPayload):
+ def __init__(self, *, state: ConnectionState, data: EmojiPayload) -> None:
- "<Emoji"
- return f"<Emoji id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>"
- f" id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>"
+ return f"<BaseEmoji id={self.id} name={self.name!r} animated={self.animated}>"
+ "<BaseEmoji" f" id={self.id} name={self.name!r} animated={self.animated}>"
+
+
+class GuildEmoji(BaseEmoji):
+class GuildEmoji(BaseEmoji):
+ """Represents a custom emoji in a guild.
+ """Represents a custom emoji in a guild.
+
+
+ Depending on the way this object was created, some attributes can
+ Depending on the way this object was created, some of the attributes can
+ have a value of ``None``.
+ have a value of ``None``.
+
+
+ .. container:: operations
+ .. collapse:: operations