Skip to content

Commit a4b2bf6

Browse files
fix(emoji): turn Emoji.is_* properties into methods (#1397)
Co-authored-by: arielle <me@arielle.codes>
1 parent eff6ca6 commit a4b2bf6

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

changelog/1223.breaking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
:attr:`Emoji.guild_id` can now be ``None`` if the emoji is owned by an application. You can use :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji` to check if this is a Guild or App Emoji.
1+
:attr:`Emoji.guild_id` can now be ``None`` if the emoji is owned by an application. You can use :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji` to check if this is a Guild or App Emoji.

changelog/1223.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add support to :class:`.Emoji` to represent application-owned emojis.
22
- New methods on :class:`Client`: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`.
3-
- New attributes on :class:`.Emoji`: :attr:`Emoji.application_id`, :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji`.
3+
- New attributes/methods on :class:`.Emoji`: :attr:`Emoji.application_id`, :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji`.

changelog/1388.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add support to :class:`.Emoji` to represent application-owned emojis.
22
- New methods on :class:`Client`: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`.
3-
- New attributes on :class:`.Emoji`: :attr:`Emoji.application_id`, :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji`.
3+
- New attributes/methods on :class:`.Emoji`: :attr:`Emoji.application_id`, :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji`.

changelog/1397.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add support to :class:`.Emoji` to represent application-owned emojis.
2+
- New methods on :class:`Client`: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`.
3+
- New attributes/methods on :class:`.Emoji`: :attr:`Emoji.application_id`, :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji`.

disnake/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ async def application_info(self) -> AppInfo:
24232423
data = await self.http.application_info()
24242424
return AppInfo(self._connection, data)
24252425

2426-
async def fetch_application_emoji(self, emoji_id: int) -> Emoji:
2426+
async def fetch_application_emoji(self, emoji_id: int, /) -> Emoji:
24272427
"""|coro|
24282428
24292429
Retrieves an application level :class:`~disnake.Emoji` based on its ID.
@@ -2482,7 +2482,7 @@ async def create_application_emoji(self, *, name: str, image: AssetBytes) -> Emo
24822482
The newly created application emoji.
24832483
"""
24842484
img = await utils._assetbytes_to_base64_data(image)
2485-
data = await self.http.create_app_emoji(self.application_id, name, img)
2485+
data = await self.http.create_app_emoji(self.application_id, name=name, image=img)
24862486
return Emoji(guild=None, state=self._connection, data=data)
24872487

24882488
async def fetch_application_emojis(self) -> List[Emoji]:

disnake/emoji.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Emoji(_EmojiTag, AssetMixin):
5454
5555
.. versionchanged:: |vnext|
5656
57-
This class can now represent app emojis. Use :attr:`Emoji.is_app_emoji` to check for this.
58-
To check if this is a guild emoji, use :attr:`Emoji.is_guild_emoji`.
57+
This class can now represent app emojis. Use :meth:`Emoji.is_app_emoji` to check for this.
58+
To check if this is a guild emoji, use :meth:`Emoji.is_guild_emoji`.
5959
6060
Attributes
6161
----------
@@ -196,19 +196,21 @@ def application_id(self) -> Optional[int]:
196196
return None
197197
return self._state.application_id
198198

199-
@property
200199
def is_guild_emoji(self) -> bool:
201-
""":class:`bool`: Whether this emoji is a guild emoji.
200+
"""Whether this emoji is a guild emoji.
202201
203202
.. versionadded:: |vnext|
203+
204+
:return type: :class:`bool`
204205
"""
205206
return self.guild_id is not None
206207

207-
@property
208208
def is_app_emoji(self) -> bool:
209-
""":class:`bool`: Whether this emoji is an application emoji.
209+
"""Whether this emoji is an application emoji.
210210
211211
.. versionadded:: |vnext|
212+
213+
:return type: :class:`bool`
212214
"""
213215
return self.guild_id is None
214216

@@ -221,10 +223,8 @@ def is_usable(self) -> bool:
221223
"""
222224
if not self.available:
223225
return False
224-
if not self.guild:
225-
# if we don't have a guild, this is an app emoji
226-
return self.available
227-
if not self._roles:
226+
# if we don't have a guild, this is an app emoji
227+
if not self.guild or not self._roles:
228228
return True
229229
emoji_roles, my_roles = self._roles, self.guild.me._roles
230230
return any(my_roles.has(role_id) for role_id in emoji_roles)
@@ -253,8 +253,8 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
253253
InvalidData
254254
The emoji data is invalid and cannot be processed.
255255
"""
256-
# this is an app emoji
257-
if self.guild is None:
256+
if self.guild_id is None:
257+
# this is an app emoji
258258
if self.application_id is None:
259259
# should never happen
260260
msg = (
@@ -264,7 +264,7 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
264264
raise InvalidData(msg)
265265

266266
return await self._state.http.delete_app_emoji(self.application_id, self.id)
267-
await self._state.http.delete_custom_emoji(self.guild.id, self.id, reason=reason)
267+
await self._state.http.delete_custom_emoji(self.guild_id, self.id, reason=reason)
268268

269269
async def edit(
270270
self, *, name: str = MISSING, roles: List[Snowflake] = MISSING, reason: Optional[str] = None
@@ -310,13 +310,8 @@ async def edit(
310310
:class:`Emoji`
311311
The newly updated emoji.
312312
"""
313-
payload = {}
314-
if name is not MISSING:
315-
payload["name"] = name
316-
if roles is not MISSING:
317-
payload["roles"] = [role.id for role in roles]
318-
319-
if self.guild is None:
313+
if self.guild_id is None:
314+
# this is an app emoji
320315
if self.application_id is None:
321316
# should never happen
322317
msg = (
@@ -325,9 +320,15 @@ async def edit(
325320
)
326321
raise InvalidData(msg)
327322

328-
data = await self._state.http.edit_app_emoji(self.application_id, self.id, name)
323+
data = await self._state.http.edit_app_emoji(self.application_id, self.id, name=name)
329324
else:
325+
payload = {}
326+
if name is not MISSING:
327+
payload["name"] = name
328+
if roles is not MISSING:
329+
payload["roles"] = [role.id for role in roles]
330+
330331
data = await self._state.http.edit_custom_emoji(
331-
self.guild.id, self.id, payload=payload, reason=reason
332+
self.guild_id, self.id, payload=payload, reason=reason
332333
)
333334
return Emoji(guild=self.guild, data=data, state=self._state)

disnake/http.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,9 @@ def get_custom_emoji(self, guild_id: Snowflake, emoji_id: Snowflake) -> Response
17741774
)
17751775
)
17761776

1777-
def create_app_emoji(self, app_id: Snowflake, name: str, image: str) -> Response[emoji.Emoji]:
1777+
def create_app_emoji(
1778+
self, app_id: Snowflake, *, name: str, image: str
1779+
) -> Response[emoji.Emoji]:
17781780
payload: Dict[str, Any] = {
17791781
"name": name,
17801782
"image": image,
@@ -1784,7 +1786,7 @@ def create_app_emoji(self, app_id: Snowflake, name: str, image: str) -> Response
17841786
return self.request(r, json=payload)
17851787

17861788
def edit_app_emoji(
1787-
self, app_id: Snowflake, emoji_id: Snowflake, name: str
1789+
self, app_id: Snowflake, emoji_id: Snowflake, *, name: str
17881790
) -> Response[emoji.Emoji]:
17891791
payload: Dict[str, Any] = {
17901792
"name": name,

0 commit comments

Comments
 (0)