@@ -38,6 +38,8 @@ class PartialEmoji(SnowflakeObject, DictSerializationMixin):
38
38
"""The custom emoji name, or standard unicode emoji in string"""
39
39
animated : bool = attrs .field (repr = True , default = False )
40
40
"""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"""
41
43
42
44
@classmethod
43
45
def from_str (cls , emoji_str : str , * , language : str = "alias" ) -> Optional ["PartialEmoji" ]:
@@ -120,7 +122,7 @@ class CustomEmoji(PartialEmoji, ClientObject):
120
122
_role_ids : List ["Snowflake_Type" ] = attrs .field (
121
123
repr = False , factory = list , converter = optional (list_converter (to_snowflake ))
122
124
)
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 ) )
124
126
125
127
@classmethod
126
128
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]
133
135
return data
134
136
135
137
@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" :
137
139
data = cls ._process_dict (data , client )
138
140
return cls (client = client , guild_id = guild_id , ** cls ._filter_kwargs (data , cls ._get_init_keys ()))
139
141
140
142
@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 ."""
143
145
return self ._client .cache .get_guild (self ._guild_id )
144
146
145
147
@property
@@ -160,6 +162,9 @@ def is_usable(self) -> bool:
160
162
if not self .available :
161
163
return False
162
164
165
+ if not self ._guild_id : # likely an application emoji
166
+ return True
167
+
163
168
guild = self .guild
164
169
return any (e_role_id in guild .me ._role_ids for e_role_id in self ._role_ids )
165
170
@@ -182,14 +187,23 @@ async def edit(
182
187
The newly modified custom emoji.
183
188
184
189
"""
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 )
191
206
192
- updated_data = await self ._client .http .modify_guild_emoji (data_payload , self ._guild_id , self .id , reason = reason )
193
207
self .update_from_dict (updated_data )
194
208
return self
195
209
@@ -202,9 +216,12 @@ async def delete(self, reason: Optional[str] = None) -> None:
202
216
203
217
"""
204
218
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." )
206
221
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 )
208
225
209
226
@property
210
227
def url (self ) -> str :
0 commit comments