@@ -122,7 +122,7 @@ class CustomEmoji(PartialEmoji, ClientObject):
122122 _role_ids : List ["Snowflake_Type" ] = attrs .field (
123123 repr = False , factory = list , converter = optional (list_converter (to_snowflake ))
124124 )
125- _guild_id : "Snowflake_Type" = attrs .field (repr = False , default = None , converter = optional (to_snowflake ))
125+ _guild_id : "Optional[ Snowflake_Type] " = attrs .field (repr = False , default = None , converter = optional (to_snowflake ))
126126
127127 @classmethod
128128 def _process_dict (cls , data : Dict [str , Any ], client : "Client" ) -> Dict [str , Any ]:
@@ -140,8 +140,8 @@ def from_dict(cls, data: Dict[str, Any], client: "Client", guild_id: int) -> "Cu
140140 return cls (client = client , guild_id = guild_id , ** cls ._filter_kwargs (data , cls ._get_init_keys ()))
141141
142142 @property
143- def guild (self ) -> "Guild" :
144- """The guild this emoji belongs to."""
143+ def guild (self ) -> "Optional[ Guild] " :
144+ """The guild this emoji belongs to, if applicable ."""
145145 return self ._client .cache .get_guild (self ._guild_id )
146146
147147 @property
@@ -162,6 +162,9 @@ def is_usable(self) -> bool:
162162 if not self .available :
163163 return False
164164
165+ if not self ._guild_id : # likely an application emoji
166+ return True
167+
165168 guild = self .guild
166169 return any (e_role_id in guild .me ._role_ids for e_role_id in self ._role_ids )
167170
@@ -184,14 +187,23 @@ async def edit(
184187 The newly modified custom emoji.
185188
186189 """
187- data_payload = dict_filter_none (
188- {
189- "name" : name ,
190- "roles" : to_snowflake_list (roles ) if roles else None ,
191- }
192- )
190+ if self ._guild_id :
191+ data_payload = dict_filter_none (
192+ {
193+ "name" : name ,
194+ "roles" : to_snowflake_list (roles ) if roles else None ,
195+ }
196+ )
197+
198+ updated_data = await self ._client .http .modify_guild_emoji (
199+ data_payload , self ._guild_id , self .id , reason = reason
200+ )
201+ else :
202+ if roles or reason :
203+ raise ValueError ("Cannot specify roles or reason for application emoji." )
204+
205+ updated_data = await self .client .http .edit_application_emoji (self .bot .app .id , self .id , name )
193206
194- updated_data = await self ._client .http .modify_guild_emoji (data_payload , self ._guild_id , self .id , reason = reason )
195207 self .update_from_dict (updated_data )
196208 return self
197209
@@ -204,9 +216,9 @@ async def delete(self, reason: Optional[str] = None) -> None:
204216
205217 """
206218 if not self ._guild_id :
207- raise ValueError ( "Cannot delete emoji, no guild id set." )
208-
209- await self ._client .http .delete_guild_emoji (self ._guild_id , self .id , reason = reason )
219+ await self . client . http . delete_application_emoji ( self . _client . app . id , self . id )
220+ else :
221+ await self ._client .http .delete_guild_emoji (self ._guild_id , self .id , reason = reason )
210222
211223 @property
212224 def url (self ) -> str :
0 commit comments