@@ -122,7 +122,7 @@ class CustomEmoji(PartialEmoji, ClientObject):
122
122
_role_ids : List ["Snowflake_Type" ] = attrs .field (
123
123
repr = False , factory = list , converter = optional (list_converter (to_snowflake ))
124
124
)
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 ))
126
126
127
127
@classmethod
128
128
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
140
140
return cls (client = client , guild_id = guild_id , ** cls ._filter_kwargs (data , cls ._get_init_keys ()))
141
141
142
142
@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 ."""
145
145
return self ._client .cache .get_guild (self ._guild_id )
146
146
147
147
@property
@@ -162,6 +162,9 @@ def is_usable(self) -> bool:
162
162
if not self .available :
163
163
return False
164
164
165
+ if not self ._guild_id : # likely an application emoji
166
+ return True
167
+
165
168
guild = self .guild
166
169
return any (e_role_id in guild .me ._role_ids for e_role_id in self ._role_ids )
167
170
@@ -184,14 +187,23 @@ async def edit(
184
187
The newly modified custom emoji.
185
188
186
189
"""
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 )
193
206
194
- updated_data = await self ._client .http .modify_guild_emoji (data_payload , self ._guild_id , self .id , reason = reason )
195
207
self .update_from_dict (updated_data )
196
208
return self
197
209
@@ -204,9 +216,9 @@ async def delete(self, reason: Optional[str] = None) -> None:
204
216
205
217
"""
206
218
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 )
210
222
211
223
@property
212
224
def url (self ) -> str :
0 commit comments