@@ -38,6 +38,8 @@ class PartialEmoji(SnowflakeObject, DictSerializationMixin):
3838 """The custom emoji name, or standard unicode emoji in string"""
3939 animated : bool = attrs .field (repr = True , default = False )
4040 """Whether this emoji is animated"""
41+ available : bool = attrs .field (repr = False , default = True )
42+ """whether this emoji can be used, may be false due to loss of Server Boosts"""
4143
4244 @classmethod
4345 def from_str (cls , emoji_str : str , * , language : str = "alias" ) -> Optional ["PartialEmoji" ]:
@@ -120,7 +122,7 @@ class CustomEmoji(PartialEmoji, ClientObject):
120122 _role_ids : List ["Snowflake_Type" ] = attrs .field (
121123 repr = False , factory = list , converter = optional (list_converter (to_snowflake ))
122124 )
123- _guild_id : "Snowflake_Type" = attrs .field (repr = False , default = None , converter = to_snowflake )
125+ _guild_id : "Optional[ Snowflake_Type] " = attrs .field (repr = False , default = None , converter = optional ( to_snowflake ) )
124126
125127 @classmethod
126128 def _process_dict (cls , data : Dict [str , Any ], client : "Client" ) -> Dict [str , Any ]:
@@ -133,13 +135,13 @@ def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]
133135 return data
134136
135137 @classmethod
136- def from_dict (cls , data : Dict [str , Any ], client : "Client" , guild_id : int ) -> "CustomEmoji" :
138+ def from_dict (cls , data : Dict [str , Any ], client : "Client" , guild_id : "Optional[Snowflake_Type]" ) -> "CustomEmoji" :
137139 data = cls ._process_dict (data , client )
138140 return cls (client = client , guild_id = guild_id , ** cls ._filter_kwargs (data , cls ._get_init_keys ()))
139141
140142 @property
141- def guild (self ) -> "Guild" :
142- """The guild this emoji belongs to."""
143+ def guild (self ) -> "Optional[ Guild] " :
144+ """The guild this emoji belongs to, if applicable ."""
143145 return self ._client .cache .get_guild (self ._guild_id )
144146
145147 @property
@@ -160,6 +162,9 @@ def is_usable(self) -> bool:
160162 if not self .available :
161163 return False
162164
165+ if not self ._guild_id : # likely an application emoji
166+ return True
167+
163168 guild = self .guild
164169 return any (e_role_id in guild .me ._role_ids for e_role_id in self ._role_ids )
165170
@@ -182,14 +187,23 @@ async def edit(
182187 The newly modified custom emoji.
183188
184189 """
185- data_payload = dict_filter_none (
186- {
187- "name" : name ,
188- "roles" : to_snowflake_list (roles ) if roles else None ,
189- }
190- )
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 )
191206
192- updated_data = await self ._client .http .modify_guild_emoji (data_payload , self ._guild_id , self .id , reason = reason )
193207 self .update_from_dict (updated_data )
194208 return self
195209
@@ -202,9 +216,12 @@ async def delete(self, reason: Optional[str] = None) -> None:
202216
203217 """
204218 if not self ._guild_id :
205- raise ValueError ("Cannot delete emoji, no guild id set." )
219+ if reason :
220+ raise ValueError ("Cannot specify reason for application emoji." )
206221
207- await self ._client .http .delete_guild_emoji (self ._guild_id , self .id , reason = reason )
222+ await self .client .http .delete_application_emoji (self ._client .app .id , self .id )
223+ else :
224+ await self ._client .http .delete_guild_emoji (self ._guild_id , self .id , reason = reason )
208225
209226 @property
210227 def url (self ) -> str :
0 commit comments