Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
stuff
생성일
2년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
268 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
526 행
복사
147 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
404 행
복사
복사
복사됨
복사
복사됨
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 App
Emoji, GuildEmoji
+from .emoji import App
lication
Emoji, 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) ->
L
ist[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) ->
L
ist[
Union[
GuildEmoji
,
App
lication
Emoji]
]
:
+
run :func:`fetch
_emojis
`.
+
+ .. versionadded:: 2.7
- def emojis(self) ->
l
ist[Emoji]:
- """
The emojis that the connected client has."""
+ def emojis(self) ->
l
ist[
GuildEmoji
|
App
Emoji]
:
+ """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
,
App
lication
Emoji
]]:
-
Optional[
:class:`.Emoji`]
+ Optional[:class:`.
GuildEmoji
` | :class:`.
App
Emoji
`]
+
+
복사
복사됨
복사
복사됨
+ async def fetch_
emojis(self) -> list[App
Emoji]:
+ async def fetch_
application_
emojis(self) -> list[App
lication
Emoji]:
+ r"""|coro|
+ r"""|coro|
복사
복사됨
복사
복사됨
+
+ Retrieves all custom :class:`App
lication
Emoji`\s from the application.
+ Retrieves all custom :class:`App
Emoji`\s from the application.
+
+
+ Raises
+ Raises
복사
복사됨
복사
복사됨
+ ------
---
+ ------
+ HTTPException
+ HTTPException
+ An error occurred fetching the emojis.
+ An error occurred fetching the emojis.
+
+
+ Returns
+ Returns
복사
복사됨
복사
복사됨
+ -------
-
+ -------
+ List[:class:`App
Emoji`]
+ List[:class:`App
lication
Emoji`]
+ 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, /) -> App
Emoji:
+ async def fetch_
application_
emoji(self, emoji_id: int, /) -> App
lication
Emoji:
+ """|coro|
+ """|coro|
복사
복사됨
복사
복사됨
+
+ Retrieves a custom :class:`App
lication
Emoji` from the application.
+ Retrieves a custom :class:`App
Emoji` from the application.
+
+
+ Parameters
+ Parameters
+ ----------
+ ----------
+ emoji_id: :class:`int`
+ emoji_id: :class:`int`
+ The emoji's ID.
+ The emoji's ID.
+
+
+ Returns
+ Returns
+ -------
+ -------
복사
복사됨
복사
복사됨
+ :class:`App
Emoji`
+ :class:`App
lication
Emoji`
+ 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,
복사
복사됨
복사
복사됨
+ ) -> App
Emoji:
+ ) -> App
lication
Emoji:
+ r"""|coro|
+ r"""|coro|
복사
복사됨
복사
복사됨
+
+ Creates a custom :class:`App
lication
Emoji` for the application.
+ Creates a custom :class:`App
Emoji` 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:`App
Emoji`
+ :class:`App
lication
Emoji`
+ 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",
"App
lication
Emoji"
)
+
"Emoji",
- from .guild_preview import GuildPreview
+
"GuildEmoji",
+
"App
Emoji"
,
+)
-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
+
+
+ .. describe:: x == y
+ .. describe:: x == y
+
+
+ Checks if two emoji are the same.
+ Checks if two emoji are the same.
+
+
+ .. describe:: x != y
+ .. describe:: x != y
+
+
+ Checks if two emoji are not the same.
+ Checks if two emoji are not the same.
+
+
+ .. describe:: hash(x)
+ .. describe:: hash(x)
+
+
+ Return the emoji's hash.
+ Return the emoji's hash.
+
+
+ .. describe:: iter(x)
+ .. describe:: iter(x)
+
+
+ Returns an iterator of ``(field, value)`` pairs. This allows this class
+ Returns an iterator of ``(field, value)`` pairs. This allows this class
+ to be used as an iterable in list/dict/etc constructions.
+ to be used as an iterable in list/dict/etc constructions.
+
+
+ .. describe:: str(x)
+ .. describe:: str(x)
+
+
복사
복사됨
복사
복사됨
+ Returns the emoji rendered for
d
iscord.
+ Returns the emoji rendered for
D
iscord.
+
+
+ Attributes
+ Attributes
+ ----------
+ ----------
+ name: :class:`str`
+ name: :class:`str`
복사
복사됨
복사
복사됨
+ The
name of the
emoji
.
+ The
emoji
's name
.
+ id: :class:`int`
+ id: :class:`int`
+ The emoji's ID.
+ The emoji's ID.
+ require_colons: :class:`bool`
+ require_colons: :class:`bool`
복사
복사됨
복사
복사됨
+
If
colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
+
Whether
colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
+ animated: :class:`bool`
+ animated: :class:`bool`
복사
복사됨
복사
복사됨
+ Whether
an
emoji is animated or not.
+ Whether
the
emoji is animated or not.
+ managed: :class:`bool`
+ managed: :class:`bool`
복사
복사됨
복사
복사됨
+
If this
emoji is managed by a Twitch integration.
+
Whether the
emoji is managed by a Twitch integration.
+ guild_id: :class:`int`
+ guild_id: :class:`int`
+ The guild ID the emoji belongs to.
+ The guild ID the emoji belongs to.
+ available: :class:`bool`
+ available: :class:`bool`
+ Whether the emoji is available for use.
+ Whether the emoji is available for use.
+ user: Optional[:class:`User`]
+ user: Optional[:class:`User`]
복사
복사됨
복사
복사됨
+ The user that created
the
emoji. This can only be retrieved using
:meth:`Guild.fetch_emoji`
and
+ The user that created
this
emoji. This can only be retrieved using
+ having the :attr:`~Permissions.manage_
emojis
` permission.
+
:meth:`Guild.fetch_emoji`
/:meth:`Guild.fetch_emojis` while
+ having the :attr:`~Permissions.manage_
guild_expressions
` permission.
+ """
+ """
+
+
+ def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload):
+ def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload):
+ self.guild_id: int = guild.id
+ self.guild_id: int = guild.id
복사
복사됨
복사
복사됨
+ super().__init__(state
, data
)
+ super().__init__(state
=state
, data
=data
)
+
+
+ def __repr__(self) -> str:
+ def __repr__(self) -> str:
복사
복사됨
복사
복사됨
+ return
(
+ return
f
"<GuildEmoji
id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>"
+
"<GuildEmoji
"
+ f"
id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>"
+ )
+
+
- ) -> Emoji:
- ) -> Emoji:
+ ) -> GuildEmoji:
+ ) -> GuildEmoji:
- :class:`Emoji`
- :class:`Emoji`
+ :class:`GuildEmoji`
+ :class:`GuildEmoji`
- return Emoji(guild=self.guild, data=data, state=self._state)
- return Emoji(guild=self.guild, data=data, state=self._state)
+ return GuildEmoji(guild=self.guild, data=data, state=self._state)
+ return GuildEmoji(guild=self.guild, data=data, state=self._state)
+
+
+
+
+Emoji = GuildEmoji
+Emoji = GuildEmoji
+
+
+
+
복사
복사됨
복사
복사됨
+class App
Emoji(BaseEmoji):
+class App
lication
Emoji(BaseEmoji):
+ """Represents a custom emoji from an application.
+ """Represents a custom emoji from an application.
+
+
+ Depending on the way this object was created, some attributes can
+ Depending on the way this object was created, some attributes can
+ have a value of ``None``.
+ have a value of ``None``.
+
+
복사
복사됨
복사
복사됨
+ .. versionadded:: 2.7
+
+ .. container:: operations
+ .. container:: operations
+
+
+ .. describe:: x == y
+ .. describe:: x == y
+
+
+ Checks if two emoji are the same.
+ Checks if two emoji are the same.
+
+
+ .. describe:: x != y
+ .. describe:: x != y
+
+
+ Checks if two emoji are not the same.
+ Checks if two emoji are not the same.
+
+
+ .. describe:: hash(x)
+ .. describe:: hash(x)
+
+
+ Return the emoji's hash.
+ Return the emoji's hash.
+
+
+ .. describe:: iter(x)
+ .. describe:: iter(x)
+
+
+ Returns an iterator of ``(field, value)`` pairs. This allows this class
+ Returns an iterator of ``(field, value)`` pairs. This allows this class
+ to be used as an iterable in list/dict/etc constructions.
+ to be used as an iterable in list/dict/etc constructions.
+
+
+ .. describe:: str(x)
+ .. describe:: str(x)
+
+
+ Returns the emoji rendered for discord.
+ Returns the emoji rendered for discord.
+
+
+ Attributes
+ Attributes
+ ----------
+ ----------
+ name: :class:`str`
+ name: :class:`str`
+ The name of the emoji.
+ The name of the emoji.
+ id: :class:`int`
+ id: :class:`int`
+ The emoji's ID.
+ The emoji's ID.
+ require_colons: :class:`bool`
+ require_colons: :class:`bool`
+ If colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
+ If colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
+ animated: :class:`bool`
+ animated: :class:`bool`
+ Whether an emoji is animated or not.
+ Whether an emoji is animated or not.
+ managed: :class:`bool`
+ managed: :class:`bool`
+ If this emoji is managed by a Twitch integration.
+ If this emoji is managed by a Twitch integration.
+ application_id: Optional[:class:`int`]
+ application_id: Optional[:class:`int`]
+ The application ID the emoji belongs to, if available.
+ The application ID the emoji belongs to, if available.
+ available: :class:`bool`
+ available: :class:`bool`
+ Whether the emoji is available for use.
+ Whether the emoji is available for use.
+ user: Optional[:class:`User`]
+ user: Optional[:class:`User`]
+ The user that created the emoji.
+ The user that created the emoji.
+ """
+ """
+
+
복사
복사됨
복사
복사됨
+ def __init__(
+ def __init__(
self, *, application_id: int, state: ConnectionState, data: EmojiPayload
):
+
self, *, application_id: int, state: ConnectionState, data: EmojiPayload
+
):
+ self.application_id: int = application_id
+ self.application_id: int = application_id
복사
복사됨
복사
복사됨
+ super().__init__(state
, data
)
+ super().__init__(state
=state
, data
=data)
+
+ def __repr__(self) -> str:
+ return "<AppEmoji" f" id={self.id} name={self.name!r} animated={self.animated}>"
+
+ @property
+ def guild(self) -> Guild:
+ """The guild this emoji belongs to. This is always `None` for :class:`AppEmoji`."""
+ return None
+
+
복사
복사됨
복사
복사됨
+ @property
+ def
__repr__
(self)
:
+ def
roles
(self)
-> list[Role]
:
+ return f"<ApplicationEmoji id={self.id} name={self.name!r} animated={self.animated}>"
+ """A :class:`list` of roles that is allowed to use this emoji. This is always empty for :class:`AppEmoji`."""
+ return []
+
+
+ def is_usable(self) -> bool:
+ def is_usable(self) -> bool:
+ """Whether the bot can use this emoji."""
+ """Whether the bot can use this emoji."""
+ return self.application_id == self._state.application_id
+ return self.application_id == self._state.application_id
+
+
+ async def delete(self) -> None:
+ async def delete(self) -> None:
+ """|coro|
+ """|coro|
복사
복사됨
복사
복사됨
+
+ Deletes the application emoji.
+ Deletes the application emoji.
복사
복사됨
복사
복사됨
+
+ You must own the emoji to do this.
+ You must own the emoji to do this.
+
+
+ Raises
+ Raises
+ ------
+ ------
+ Forbidden
+ Forbidden
+ You are not allowed to delete the emoji.
+ You are not allowed to delete the emoji.
+ HTTPException
+ HTTPException
+ An error occurred deleting the emoji.
+ An error occurred deleting the emoji.
+ """
+ """
복사
복사됨
복사
복사됨
+
+ await self._state.http.delete_application_emoji(self.application_id, self.id)
+ await self._state.http.delete_application_emoji(self.application_id, self.id)
+ if self._state.cache_app_emojis and self._state.get_emoji(self.id):
+ if self._state.cache_app_emojis and self._state.get_emoji(self.id):
+ self._state._remove_emoji(self)
+ self._state._remove_emoji(self)
+
+
+ async def edit(
+ async def edit(
+ self,
+ self,
+ *,
+ *,
+ name: str = MISSING,
+ name: str = MISSING,
복사
복사됨
복사
복사됨
+ ) -> App
Emoji:
+ ) -> App
lication
Emoji:
+ r"""|coro|
+ r"""|coro|
복사
복사됨
복사
복사됨
+
+ Edits the application emoji.
+ Edits the application emoji.
복사
복사됨
복사
복사됨
+
+ You must own the emoji to do this.
+ You must own the emoji to do this.
+
+
+ Parameters
+ Parameters
복사
복사됨
복사
복사됨
+ ----------
-
+ ----------
+ name: :class:`str`
+ name: :class:`str`
+ The new emoji name.
+ The new emoji name.
+
+
+ Raises
+ Raises
복사
복사됨
복사
복사됨
+ ------
-
+ ------
+ Forbidden
+ Forbidden
+ You are not allowed to edit the emoji.
+ You are not allowed to edit the emoji.
+ HTTPException
+ HTTPException
+ An error occurred editing the emoji.
+ An error occurred editing the emoji.
+
+
+ Returns
+ Returns
복사
복사됨
복사
복사됨
+ -------
-
+ -------
+ :class:`App
Emoji`
+ :class:`App
lication
Emoji`
+ The newly updated emoji.
+ The newly updated emoji.
+ """
+ """
복사
복사됨
복사
복사됨
+
+ payload = {}
+ payload = {}
+ if name is not MISSING:
+ if name is not MISSING:
+ payload["name"] = name
+ payload["name"] = name
+
+
+ data = await self._state.http.edit_application_emoji(
+ data = await self._state.http.edit_application_emoji(
+ self.application_id, self.id, payload=payload
+ self.application_id, self.id, payload=payload
+ )
+ )
복사
복사됨
복사
복사됨
+ return self._state.
maybe_
store_
app
_emoji(self.application_id, data)
+ return self._state.
store_
application
_emoji(self.application_id, data)
diff --git a/
discord
/http.py b/
discord
/http.py
diff --git a/
disnake/ext/commands/bot.py b/disnake/ext/commands/bot.py
--- a/
discord
/http.py
--- a/disnake/ext/commands/bot.py
+++ b/
discord
/http.py
+++ b/disnake/ext/commands/bot.py
+ def get_all_application_emojis(
+
+
self, application_id: Snowflake
+ cache_app_emojis: :class:`bool`
+
) -> Response[
l
ist[emoji.Emoji]]:
+ Whether to automatically fetch and cache the application's emojis on startup and when fetching.
+ Defaults to ``False``.
+ cache_app_emojis: bool = False,
+ cache_app_emojis: bool = False,
+
+ cache_app_emojis: :class:`bool`
+ Whether to automatically fetch and cache the application's emojis on startup and when fetching.
+ Defaults to ``False``.
+ cache_app_emojis: bool = False,
+ cache_app_emojis: bool = False,
diff --git a/disnake
/http.py b/
disnake
/http.py
--- a/
disnake
/http.py
+++ b/
disnake
/http.py
+ def get_all_application_emojis(
self, application_id: Snowflake
) -> Response[
L
ist[emoji.Emoji]]:
+ return self.request(
+ return self.request(
복사
복사됨
복사
복사됨
+ Route(
+ Route(
"GET",
"/applications/{application_id}/emojis",
application_id=application_id
)
+
"GET",
+
"/applications/{application_id}/emojis",
+
application_id=application_id
,
+
)
+ )
+ )
+
+
+ def get_application_emoji(
+ def get_application_emoji(
+ self, application_id: Snowflake, emoji_id: Snowflake
+ self, application_id: Snowflake, emoji_id: Snowflake
+ ) -> Response[emoji.Emoji]:
+ ) -> Response[emoji.Emoji]:
+ return self.request(
+ return self.request(
+ Route(
+ Route(
+ "GET",
+ "GET",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ application_id=application_id,
+ application_id=application_id,
+ emoji_id=emoji_id,
+ emoji_id=emoji_id,
+ )
+ )
+ )
+ )
+
+
+ def create_application_emoji(
+ def create_application_emoji(
+ self,
+ self,
+ application_id: Snowflake,
+ application_id: Snowflake,
+ name: str,
+ name: str,
복사
복사됨
복사
복사됨
+ image:
bytes
,
+ image:
str
,
+ ) -> Response[emoji.Emoji]:
+ ) -> Response[emoji.Emoji]:
복사
복사됨
복사
복사됨
+ payload = {
+ payload = {
"name": name, "image": image}
+ "name": name,
+ r = Route("POST",
"/applications/{application_id}/emojis",
application_id=application_id
)
+ "image": image,
+ }
+
+ r = Route(
+ "POST",
+
"/applications/{application_id}/emojis",
+
application_id=application_id
,
+
)
+ return self.request(r, json=payload)
+ return self.request(r, json=payload)
+
+
+ def delete_application_emoji(
+ def delete_application_emoji(
+ self,
+ self,
+ application_id: Snowflake,
+ application_id: Snowflake,
+ emoji_id: Snowflake,
+ emoji_id: Snowflake,
+ ) -> Response[None]:
+ ) -> Response[None]:
+ r = Route(
+ r = Route(
+ "DELETE",
+ "DELETE",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ application_id=application_id,
+ application_id=application_id,
+ emoji_id=emoji_id,
+ emoji_id=emoji_id,
+ )
+ )
+ return self.request(r)
+ return self.request(r)
+
+
+ def edit_application_emoji(
+ def edit_application_emoji(
+ self,
+ self,
+ application_id: Snowflake,
+ application_id: Snowflake,
+ emoji_id: Snowflake,
+ emoji_id: Snowflake,
+ *,
+ *,
+ payload: dict[str, Any],
+ payload: dict[str, Any],
+ ) -> Response[emoji.Emoji]:
+ ) -> Response[emoji.Emoji]:
+ r = Route(
+ r = Route(
+ "PATCH",
+ "PATCH",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ "/applications/{application_id}/emojis/{emoji_id}",
+ application_id=application_id,
+ application_id=application_id,
+ emoji_id=emoji_id,
+ emoji_id=emoji_id,
+ )
+ )
+ return self.request(r, json=payload)
+ return self.request(r, json=payload)
+
+
복사
복사됨
복사
복사됨
diff --git a/
discord
/state.py b/
discord
/state.py
diff --git a/
disnake
/state.py b/
disnake
/state.py
--- a/
discord
/state.py
--- a/
disnake
/state.py
+++ b/
discord
/state.py
+++ b/
disnake
/state.py
-from .emoji import Emoji
-from .emoji import Emoji
복사
복사됨
복사
복사됨
+from .emoji import App
Emoji, Emoji, GuildEmoji
+from .emoji import App
lication
Emoji, Emoji, GuildEmoji
+ self.cache_app_emojis: bool =
options.get("
cache_app_emojis
", False)
+ cache_app_emojis: bool = False,
+ self.cache_app_emojis: bool =
cache_app_emojis
+
+
복사
복사됨
복사
복사됨
- self._emojis: Dict[int, Emoji] = {}
+ self._emojis: Dict[int, Emoji, ApplicationEmoji] = {}
- def store_emoji(self, guild: Guild, data: EmojiPayload) -> Emoji:
- def store_emoji(self, guild: Guild, data: EmojiPayload) -> Emoji:
+ def store_emoji(self, guild: Guild, data: EmojiPayload) -> GuildEmoji:
+ def store_emoji(self, guild: Guild, data: EmojiPayload) -> GuildEmoji:
- self._emojis[emoji_id] = emoji = Emoji(guild=guild, state=self, data=data)
- self._emojis[emoji_id] = emoji = Emoji(guild=guild, state=self, data=data)
+ self._emojis[emoji_id] = emoji = GuildEmoji(guild=guild, state=self, data=data)
+ self._emojis[emoji_id] = emoji = GuildEmoji(guild=guild, state=self, data=data)
+ return emoji
+ return emoji
+
+
복사
복사됨
복사
복사됨
+ def
maybe_
store_
app
_emoji(
+ def
store_
application
_emoji(
self, application_id: int, data: EmojiPayload
) -> App
lication
Emoji:
+
self, application_id: int, data: EmojiPayload
+ emoji = App
lication
Emoji(application_id=application_id, state=self, data=data)
+
) -> App
Emoji:
+ # the id will be present here
+ emoji = App
Emoji(application_id=application_id, state=self, data=data)
+ if self.cache_app_emojis:
+ if self.cache_app_emojis:
+ emoji_id = int(data["id"]) # type: ignore
+ emoji_id = int(data["id"]) # type: ignore
+ self._emojis[emoji_id] = emoji
+ self._emojis[emoji_id] = emoji
- self._emojis.pop(emoji.id, None)
- self._emojis.pop(emoji.id, None)
복사
복사됨
복사
복사됨
+ self._remove_emoji(emoji
)
+ self._remove_emoji(emoji
.id
)
- def emojis(self) ->
l
ist[Emoji]:
- def emojis(self) ->
L
ist[Emoji]:
+ def emojis(self) ->
l
ist[
GuildEmoji
|
App
Emoji]
:
+ def emojis(self) ->
L
ist[
Union[
GuildEmoji
,
App
lication
Emoji]
]
:
- def get_emoji(self, emoji_id:
int
| None
) ->
Emoji
| None
:
- def get_emoji(self, emoji_id:
Optional[
int
]
) ->
Optional[
Emoji
]
:
+ def get_emoji(self, emoji_id:
int
| None
) ->
GuildEmoji
|
App
Emoji
| None
:
+ def get_emoji(self, emoji_id:
Optional[
int
]
) ->
Optional[Union[
GuildEmoji
,
App
lication
Emoji
]]
:
+ def _remove_emoji(self, emoji:
GuildEmoji
|
App
Emoji
) -> None:
+ def _remove_emoji(self, emoji:
Union[
GuildEmoji
,
App
lication
Emoji
]
) -> None:
+ self._emojis.pop(emoji.id, None)
+ self._emojis.pop(emoji.id, None)
+
+
+ if self.cache_app_emojis and self.application_id:
+ if self.cache_app_emojis and self.application_id:
+ data = await self.http.get_all_application_emojis(self.application_id)
+ data = await self.http.get_all_application_emojis(self.application_id)
+ for e in data.get("items", []):
+ for e in data.get("items", []):
복사
복사됨
복사
복사됨
+ self.
maybe_
store_
app
_emoji(self.application_id, e)
+ self.
store_
application
_emoji(self.application_id, e)
+
diff --git a/docs/api/models.rst b/docs/api/models.rst
--- a/docs/api/models.rst
+++ b/docs/api/models.rst
-.. attributetable:: Emoji
+.. attributetable:: GuildEmoji
-.. autoclass:: Emoji()
+.. autoclass:: GuildEmoji()
+ :members:
+ :inherited-members:
+
+.. attributetable:: AppEmoji
+
+
복사
복사됨
복사
복사됨
+.. autoclass:: AppEmoji()
저장된 비교 결과
원본
파일 열기
diff --git a/discord/client.py b/discord/client.py --- a/discord/client.py +++ b/discord/client.py -from .emoji import Emoji +from .emoji import AppEmoji, GuildEmoji + cache_app_emojis: :class:`bool` + Whether to automatically fetch and cache the application's emojis on startup and when fetching. Defaults to ``False``. + + .. warning:: + + There are no events related to application emojis - if any are created/deleted on the + Developer Dashboard while the client is running, the cache will not be updated until you manually + 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. + + .. note:: + + This only includes the application's emojis if :attr:`~Client.cache_app_emojis` is ``True``. + """ - def get_emoji(self, id: int, /) -> Emoji | None: + def get_emoji(self, id: int, /) -> GuildEmoji | AppEmoji | None: - Optional[:class:`.Emoji`] + Optional[:class:`.GuildEmoji` | :class:`.AppEmoji`] + + async def fetch_emojis(self) -> list[AppEmoji]: + r"""|coro| + + Retrieves all custom :class:`AppEmoji`\s from the application. + + Raises + --------- + HTTPException + An error occurred fetching the emojis. + + Returns + -------- + List[:class:`AppEmoji`] + The retrieved emojis. + """ + data = await self._state.http.get_all_application_emojis(self.application_id) + return [ + self._state.maybe_store_app_emoji(self.application_id, d) + for d in data["items"] + ] + + async def fetch_emoji(self, emoji_id: int, /) -> AppEmoji: + """|coro| + + Retrieves a custom :class:`AppEmoji` from the application. + + Parameters + ---------- + emoji_id: :class:`int` + The emoji's ID. + + Returns + ------- + :class:`AppEmoji` + The retrieved emoji. + + Raises + ------ + NotFound + The emoji requested could not be found. + HTTPException + An error occurred fetching the emoji. + """ + data = await self._state.http.get_application_emoji( + self.application_id, emoji_id + ) + return self._state.maybe_store_app_emoji(self.application_id, data) + + async def create_emoji( + self, + *, + name: str, + image: bytes, + ) -> AppEmoji: + r"""|coro| + + Creates a custom :class:`AppEmoji` for the application. + + There is currently a limit of 2000 emojis per application. + + Parameters + ----------- + name: :class:`str` + The emoji name. Must be at least 2 characters. + image: :class:`bytes` + The :term:`py:bytes-like object` representing the image data to use. + Only JPG, PNG and GIF images are supported. + + Raises + ------- + Forbidden + You are not allowed to create emojis. + HTTPException + An error occurred creating an emoji. + + Returns + -------- + :class:`AppEmoji` + The created emoji. + """ + + img = utils._bytes_to_base64_data(image) + data = await self._state.http.create_application_emoji( + self.application_id, name, img + ) + return self._state.maybe_store_app_emoji(self.application_id, data) + + async def delete_emoji( + self, emoji: Snowflake, *, reason: str | None = None + ) -> 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", + "GuildEmoji", + "AppEmoji", +) -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): + "application_id", - def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload): - self.guild_id: int = guild.id + def __init__(self, *, state: ConnectionState, data: EmojiPayload): - "<Emoji" - f" id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>" + "<BaseEmoji" f" id={self.id} name={self.name!r} animated={self.animated}>" + +class GuildEmoji(BaseEmoji): + """Represents a custom emoji in a guild. + + 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. + """ + + def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload): + self.guild_id: int = guild.id + super().__init__(state, data) + + def __repr__(self) -> str: + return ( + "<GuildEmoji" + f" id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>" + ) + - ) -> Emoji: + ) -> GuildEmoji: - :class:`Emoji` + :class:`GuildEmoji` - return Emoji(guild=self.guild, data=data, state=self._state) + return GuildEmoji(guild=self.guild, data=data, state=self._state) + + +Emoji = GuildEmoji + + +class AppEmoji(BaseEmoji): + """Represents a custom emoji from an application. + + Depending on the way this object was created, some attributes can + have a value of ``None``. + + .. versionadded:: 2.7 + + .. 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. + application_id: Optional[:class:`int`] + The application ID the emoji belongs to, if available. + available: :class:`bool` + Whether the emoji is available for use. + user: Optional[:class:`User`] + The user that created the emoji. + """ + + def __init__( + self, *, application_id: int, state: ConnectionState, data: EmojiPayload + ): + self.application_id: int = application_id + super().__init__(state, data) + + def __repr__(self) -> str: + return "<AppEmoji" f" id={self.id} name={self.name!r} animated={self.animated}>" + + @property + def guild(self) -> Guild: + """The guild this emoji belongs to. This is always `None` for :class:`AppEmoji`.""" + return None + + @property + def roles(self) -> list[Role]: + """A :class:`list` of roles that is allowed to use this emoji. This is always empty for :class:`AppEmoji`.""" + return [] + + def is_usable(self) -> bool: + """Whether the bot can use this emoji.""" + return self.application_id == self._state.application_id + + async def delete(self) -> None: + """|coro| + + Deletes the application emoji. + + You must own the emoji to do this. + + Raises + ------ + Forbidden + You are not allowed to delete the emoji. + HTTPException + An error occurred deleting the emoji. + """ + + await self._state.http.delete_application_emoji(self.application_id, self.id) + if self._state.cache_app_emojis and self._state.get_emoji(self.id): + self._state._remove_emoji(self) + + async def edit( + self, + *, + name: str = MISSING, + ) -> AppEmoji: + r"""|coro| + + Edits the application emoji. + + You must own the emoji to do this. + + Parameters + ----------- + name: :class:`str` + The new emoji name. + + Raises + ------- + Forbidden + You are not allowed to edit the emoji. + HTTPException + An error occurred editing the emoji. + + Returns + -------- + :class:`AppEmoji` + The newly updated emoji. + """ + + payload = {} + if name is not MISSING: + payload["name"] = name + + data = await self._state.http.edit_application_emoji( + self.application_id, self.id, payload=payload + ) + return self._state.maybe_store_app_emoji(self.application_id, data) diff --git a/discord/http.py b/discord/http.py --- a/discord/http.py +++ b/discord/http.py + def get_all_application_emojis( + self, application_id: Snowflake + ) -> Response[list[emoji.Emoji]]: + return self.request( + Route( + "GET", + "/applications/{application_id}/emojis", + application_id=application_id, + ) + ) + + def get_application_emoji( + self, application_id: Snowflake, emoji_id: Snowflake + ) -> Response[emoji.Emoji]: + return self.request( + Route( + "GET", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + ) + + def create_application_emoji( + self, + application_id: Snowflake, + name: str, + image: bytes, + ) -> Response[emoji.Emoji]: + payload = { + "name": name, + "image": image, + } + + r = Route( + "POST", + "/applications/{application_id}/emojis", + application_id=application_id, + ) + return self.request(r, json=payload) + + def delete_application_emoji( + self, + application_id: Snowflake, + emoji_id: Snowflake, + ) -> Response[None]: + r = Route( + "DELETE", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + return self.request(r) + + def edit_application_emoji( + self, + application_id: Snowflake, + emoji_id: Snowflake, + *, + payload: dict[str, Any], + ) -> Response[emoji.Emoji]: + r = Route( + "PATCH", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + return self.request(r, json=payload) + diff --git a/discord/state.py b/discord/state.py --- a/discord/state.py +++ b/discord/state.py -from .emoji import Emoji +from .emoji import AppEmoji, Emoji, GuildEmoji + self.cache_app_emojis: bool = options.get("cache_app_emojis", False) + - def store_emoji(self, guild: Guild, data: EmojiPayload) -> Emoji: + def store_emoji(self, guild: Guild, data: EmojiPayload) -> GuildEmoji: - self._emojis[emoji_id] = emoji = Emoji(guild=guild, state=self, data=data) + self._emojis[emoji_id] = emoji = GuildEmoji(guild=guild, state=self, data=data) + return emoji + + def maybe_store_app_emoji( + self, application_id: int, data: EmojiPayload + ) -> AppEmoji: + # the id will be present here + emoji = AppEmoji(application_id=application_id, state=self, data=data) + if self.cache_app_emojis: + emoji_id = int(data["id"]) # type: ignore + self._emojis[emoji_id] = emoji - self._emojis.pop(emoji.id, None) + self._remove_emoji(emoji) - def emojis(self) -> list[Emoji]: + def emojis(self) -> list[GuildEmoji | AppEmoji]: - def get_emoji(self, emoji_id: int | None) -> Emoji | None: + def get_emoji(self, emoji_id: int | None) -> GuildEmoji | AppEmoji | None: + def _remove_emoji(self, emoji: GuildEmoji | AppEmoji) -> None: + self._emojis.pop(emoji.id, None) + + if self.cache_app_emojis and self.application_id: + data = await self.http.get_all_application_emojis(self.application_id) + for e in data.get("items", []): + self.maybe_store_app_emoji(self.application_id, e) + diff --git a/docs/api/models.rst b/docs/api/models.rst --- a/docs/api/models.rst +++ b/docs/api/models.rst -.. attributetable:: Emoji +.. attributetable:: GuildEmoji -.. autoclass:: Emoji() +.. autoclass:: GuildEmoji() + :members: + :inherited-members: + +.. attributetable:: AppEmoji + +.. autoclass:: AppEmoji()
수정본
파일 열기
diff --git a/disnake/client.py b/disnake/client.py --- a/disnake/client.py +++ b/disnake/client.py -from .emoji import Emoji +from .emoji import ApplicationEmoji, GuildEmoji + cache_app_emojis: bool = False, + cache_app_emojis=cache_app_emojis, + cache_app_emojis: bool, + cache_app_emojis=cache_app_emojis, - def emojis(self) -> List[Emoji]: - """List[:class:`.Emoji`]: The emojis that the connected client has.""" + def emojis(self) -> List[Union[GuildEmoji, ApplicationEmoji]]: + """The emojis that the connected client has. + + .. note:: + This only includes the application's emojis if :attr:`~Client.cache_app_emojis` is + ``True``. + """ - def get_emoji(self, id: int, /) -> Optional[Emoji]: + def get_emoji(self, id: int, /) -> Optional[Union[GuildEmoji, ApplicationEmoji]]: + + async def fetch_application_emojis(self) -> list[ApplicationEmoji]: + r"""|coro| + Retrieves all custom :class:`ApplicationEmoji`\s from the application. + + Raises + ------ + HTTPException + An error occurred fetching the emojis. + + Returns + ------- + List[:class:`ApplicationEmoji`] + The retrieved emojis. + """ + data = await self._connection.http.get_all_application_emojis(self.application_id) + return [ + self._connection.store_application_emoji(self.application_id, d) for d in data["items"] + ] + + async def fetch_application_emoji(self, emoji_id: int, /) -> ApplicationEmoji: + """|coro| + Retrieves a custom :class:`ApplicationEmoji` from the application. + + Parameters + ---------- + emoji_id: :class:`int` + The emoji's ID. + + Returns + ------- + :class:`ApplicationEmoji` + The retrieved emoji. + + Raises + ------ + NotFound + The emoji requested could not be found. + HTTPException + An error occurred fetching the emoji. + """ + data = await self._connection.http.get_application_emoji(self.application_id, emoji_id) + return self._connection.store_application_emoji(self.application_id, data) + + async def create_application_emoji( + self, + *, + name: str, + image: bytes, + ) -> ApplicationEmoji: + r"""|coro| + Creates a custom :class:`ApplicationEmoji` for the application. + There is currently a limit of 2000 emojis per application. + + Parameters + ---------- + name: :class:`str` + The emoji name. Must be at least 2 characters. + image: :class:`bytes` + The :term:`py:bytes-like object` representing the image data to use. + Only JPG, PNG and GIF images are supported. + + Raises + ------ + Forbidden + You are not allowed to create emojis. + HTTPException + An error occurred creating an emoji. + + Returns + ------- + :class:`ApplicationEmoji` + The created emoji. + """ + img = utils._bytes_to_base64_data(image) + data = await self._connection.http.create_application_emoji(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 --- a/disnake/emoji.py +++ b/disnake/emoji.py -from typing import TYPE_CHECKING, Any, Iterator, List, Optional, Tuple, Union +from typing import TYPE_CHECKING, Any, Iterator, List, Optional, Tuple -__all__ = ("Emoji",) +__all__ = ("Emoji", "GuildEmoji", "ApplicationEmoji") - from .guild_preview import GuildPreview -class Emoji(_EmojiTag, AssetMixin): +class BaseEmoji(_EmojiTag, AssetMixin): + "application_id", - def __init__( - self, *, guild: Union[Guild, GuildPreview], state: ConnectionState, data: EmojiPayload - ) -> None: - self.guild_id: int = guild.id + def __init__(self, *, state: ConnectionState, data: EmojiPayload) -> None: - return f"<Emoji 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}>" + +class GuildEmoji(BaseEmoji): + """Represents a custom emoji in a guild. + + Depending on the way this object was created, some of the attributes can + have a value of ``None``. + + .. collapse:: 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 emoji's name. + id: :class:`int` + The emoji's ID. + require_colons: :class:`bool` + Whether colons are required to use this emoji in the client (:PJSalt: vs PJSalt). + animated: :class:`bool` + Whether the emoji is animated or not. + managed: :class:`bool` + Whether the 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 this emoji. This can only be retrieved using + :meth:`Guild.fetch_emoji`/:meth:`Guild.fetch_emojis` while + having the :attr:`~Permissions.manage_guild_expressions` permission. + """ + + def __init__(self, *, guild: Guild, state: ConnectionState, data: EmojiPayload): + self.guild_id: int = guild.id + super().__init__(state=state, data=data) + + def __repr__(self) -> str: + return f"<GuildEmoji id={self.id} name={self.name!r} animated={self.animated} managed={self.managed}>" + - ) -> Emoji: + ) -> GuildEmoji: - :class:`Emoji` + :class:`GuildEmoji` - return Emoji(guild=self.guild, data=data, state=self._state) + return GuildEmoji(guild=self.guild, data=data, state=self._state) + + +Emoji = GuildEmoji + + +class ApplicationEmoji(BaseEmoji): + """Represents a custom emoji from an application. + + 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. + application_id: Optional[:class:`int`] + The application ID the emoji belongs to, if available. + available: :class:`bool` + Whether the emoji is available for use. + user: Optional[:class:`User`] + The user that created the emoji. + """ + + def __init__(self, *, application_id: int, state: ConnectionState, data: EmojiPayload): + self.application_id: int = application_id + super().__init__(state=state, data=data) + + def __repr__(self): + return f"<ApplicationEmoji id={self.id} name={self.name!r} animated={self.animated}>" + + def is_usable(self) -> bool: + """Whether the bot can use this emoji.""" + return self.application_id == self._state.application_id + + async def delete(self) -> None: + """|coro| + Deletes the application emoji. + You must own the emoji to do this. + + Raises + ------ + Forbidden + You are not allowed to delete the emoji. + HTTPException + An error occurred deleting the emoji. + """ + await self._state.http.delete_application_emoji(self.application_id, self.id) + if self._state.cache_app_emojis and self._state.get_emoji(self.id): + self._state._remove_emoji(self) + + async def edit( + self, + *, + name: str = MISSING, + ) -> ApplicationEmoji: + r"""|coro| + Edits the application emoji. + You must own the emoji to do this. + + Parameters + ---------- + name: :class:`str` + The new emoji name. + + Raises + ------ + Forbidden + You are not allowed to edit the emoji. + HTTPException + An error occurred editing the emoji. + + Returns + ------- + :class:`ApplicationEmoji` + The newly updated emoji. + """ + payload = {} + if name is not MISSING: + payload["name"] = name + + data = await self._state.http.edit_application_emoji( + self.application_id, self.id, payload=payload + ) + return self._state.store_application_emoji(self.application_id, data) diff --git a/disnake/ext/commands/bot.py b/disnake/ext/commands/bot.py --- a/disnake/ext/commands/bot.py +++ b/disnake/ext/commands/bot.py + + cache_app_emojis: :class:`bool` + Whether to automatically fetch and cache the application's emojis on startup and when fetching. + Defaults to ``False``. + cache_app_emojis: bool = False, + cache_app_emojis: bool = False, + + cache_app_emojis: :class:`bool` + Whether to automatically fetch and cache the application's emojis on startup and when fetching. + Defaults to ``False``. + cache_app_emojis: bool = False, + cache_app_emojis: bool = False, diff --git a/disnake/http.py b/disnake/http.py --- a/disnake/http.py +++ b/disnake/http.py + def get_all_application_emojis(self, application_id: Snowflake) -> Response[List[emoji.Emoji]]: + return self.request( + Route("GET", "/applications/{application_id}/emojis", application_id=application_id) + ) + + def get_application_emoji( + self, application_id: Snowflake, emoji_id: Snowflake + ) -> Response[emoji.Emoji]: + return self.request( + Route( + "GET", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + ) + + def create_application_emoji( + self, + application_id: Snowflake, + name: str, + image: str, + ) -> Response[emoji.Emoji]: + payload = {"name": name, "image": image} + r = Route("POST", "/applications/{application_id}/emojis", application_id=application_id) + return self.request(r, json=payload) + + def delete_application_emoji( + self, + application_id: Snowflake, + emoji_id: Snowflake, + ) -> Response[None]: + r = Route( + "DELETE", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + return self.request(r) + + def edit_application_emoji( + self, + application_id: Snowflake, + emoji_id: Snowflake, + *, + payload: dict[str, Any], + ) -> Response[emoji.Emoji]: + r = Route( + "PATCH", + "/applications/{application_id}/emojis/{emoji_id}", + application_id=application_id, + emoji_id=emoji_id, + ) + return self.request(r, json=payload) + diff --git a/disnake/state.py b/disnake/state.py --- a/disnake/state.py +++ b/disnake/state.py -from .emoji import Emoji +from .emoji import ApplicationEmoji, Emoji, GuildEmoji + cache_app_emojis: bool = False, + self.cache_app_emojis: bool = cache_app_emojis + - self._emojis: Dict[int, Emoji] = {} + self._emojis: Dict[int, Emoji, ApplicationEmoji] = {} - def store_emoji(self, guild: Guild, data: EmojiPayload) -> Emoji: + def store_emoji(self, guild: Guild, data: EmojiPayload) -> GuildEmoji: - self._emojis[emoji_id] = emoji = Emoji(guild=guild, state=self, data=data) + self._emojis[emoji_id] = emoji = GuildEmoji(guild=guild, state=self, data=data) + return emoji + + def store_application_emoji(self, application_id: int, data: EmojiPayload) -> ApplicationEmoji: + emoji = ApplicationEmoji(application_id=application_id, state=self, data=data) + if self.cache_app_emojis: + emoji_id = int(data["id"]) # type: ignore + self._emojis[emoji_id] = emoji - self._emojis.pop(emoji.id, None) + self._remove_emoji(emoji.id) - def emojis(self) -> List[Emoji]: + def emojis(self) -> List[Union[GuildEmoji, ApplicationEmoji]]: - def get_emoji(self, emoji_id: Optional[int]) -> Optional[Emoji]: + def get_emoji(self, emoji_id: Optional[int]) -> Optional[Union[GuildEmoji, ApplicationEmoji]]: + def _remove_emoji(self, emoji: Union[GuildEmoji, ApplicationEmoji]) -> None: + self._emojis.pop(emoji.id, None) + + if self.cache_app_emojis and self.application_id: + data = await self.http.get_all_application_emojis(self.application_id) + for e in data.get("items", []): + self.store_application_emoji(self.application_id, e) +
비교하기