2929from .utils import SnowflakeList , snowflake_time , MISSING
3030from .partial_emoji import _EmojiTag , PartialEmoji
3131from .user import User
32+ from .app_commands .errors import MissingApplicationID
33+ from .object import Object
3234
3335# fmt: off
3436__all__ = (
@@ -93,6 +95,10 @@ class Emoji(_EmojiTag, AssetMixin):
9395 user: Optional[:class:`User`]
9496 The user that created the emoji. This can only be retrieved using :meth:`Guild.fetch_emoji` and
9597 having :attr:`~Permissions.manage_emojis`.
98+
99+ Or if :meth:`.is_application_owned` is ``True``, this is the team member that uploaded
100+ the emoji, or the bot user if it was uploaded using the API and this can
101+ only be retrieved using :meth:`~discord.Client.fetch_application_emoji` or :meth:`~discord.Client.fetch_application_emojis`.
96102 """
97103
98104 __slots__ : Tuple [str , ...] = (
@@ -108,7 +114,7 @@ class Emoji(_EmojiTag, AssetMixin):
108114 'available' ,
109115 )
110116
111- def __init__ (self , * , guild : Guild , state : ConnectionState , data : EmojiPayload ) -> None :
117+ def __init__ (self , * , guild : Snowflake , state : ConnectionState , data : EmojiPayload ) -> None :
112118 self .guild_id : int = guild .id
113119 self ._state : ConnectionState = state
114120 self ._from_data (data )
@@ -196,20 +202,32 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
196202
197203 Deletes the custom emoji.
198204
199- You must have :attr:`~Permissions.manage_emojis` to do this.
205+ You must have :attr:`~Permissions.manage_emojis` to do this if
206+ :meth:`.is_application_owned` is ``False``.
200207
201208 Parameters
202209 -----------
203210 reason: Optional[:class:`str`]
204211 The reason for deleting this emoji. Shows up on the audit log.
205212
213+ This does not apply if :meth:`.is_application_owned` is ``True``.
214+
206215 Raises
207216 -------
208217 Forbidden
209218 You are not allowed to delete emojis.
210219 HTTPException
211220 An error occurred deleting the emoji.
221+ MissingApplicationID
222+ The emoji is owned by an application but the application ID is missing.
212223 """
224+ if self .is_application_owned ():
225+ application_id = self ._state .application_id
226+ if application_id is None :
227+ raise MissingApplicationID
228+
229+ await self ._state .http .delete_application_emoji (application_id , self .id )
230+ return
213231
214232 await self ._state .http .delete_custom_emoji (self .guild_id , self .id , reason = reason )
215233
@@ -231,15 +249,22 @@ async def edit(
231249 The new emoji name.
232250 roles: List[:class:`~discord.abc.Snowflake`]
233251 A list of roles that can use this emoji. An empty list can be passed to make it available to everyone.
252+
253+ This does not apply if :meth:`.is_application_owned` is ``True``.
254+
234255 reason: Optional[:class:`str`]
235256 The reason for editing this emoji. Shows up on the audit log.
236257
258+ This does not apply if :meth:`.is_application_owned` is ``True``.
259+
237260 Raises
238261 -------
239262 Forbidden
240263 You are not allowed to edit emojis.
241264 HTTPException
242265 An error occurred editing the emoji.
266+ MissingApplicationID
267+ The emoji is owned by an application but the application ID is missing
243268
244269 Returns
245270 --------
@@ -253,5 +278,25 @@ async def edit(
253278 if roles is not MISSING :
254279 payload ['roles' ] = [role .id for role in roles ]
255280
281+ if self .is_application_owned ():
282+ application_id = self ._state .application_id
283+ if application_id is None :
284+ raise MissingApplicationID
285+
286+ payload .pop ('roles' , None )
287+ data = await self ._state .http .edit_application_emoji (
288+ application_id ,
289+ self .id ,
290+ payload = payload ,
291+ )
292+ return Emoji (guild = Object (0 ), data = data , state = self ._state )
293+
256294 data = await self ._state .http .edit_custom_emoji (self .guild_id , self .id , payload = payload , reason = reason )
257295 return Emoji (guild = self .guild , data = data , state = self ._state ) # type: ignore # if guild is None, the http request would have failed
296+
297+ def is_application_owned (self ) -> bool :
298+ """:class:`bool`: Whether the emoji is owned by an application.
299+
300+ .. versionadded:: 2.5
301+ """
302+ return self .guild_id == 0
0 commit comments