Skip to content

Commit c6f31d9

Browse files
committed
fix(emoji): turn Emoji.is_* properties into methods
This reverts commit c66d0fe.
1 parent c66d0fe commit c6f31d9

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-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`.

disnake/client.py

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

2421-
async def fetch_application_emoji(self, emoji_id: int) -> Emoji:
2421+
async def fetch_application_emoji(self, emoji_id: int, /) -> Emoji:
24222422
"""|coro|
24232423
24242424
Retrieves an application level :class:`~disnake.Emoji` based on its ID.
@@ -2477,7 +2477,7 @@ async def create_application_emoji(self, *, name: str, image: AssetBytes) -> Emo
24772477
The newly created application emoji.
24782478
"""
24792479
img = await utils._assetbytes_to_base64_data(image)
2480-
data = await self.http.create_app_emoji(self.application_id, name, img)
2480+
data = await self.http.create_app_emoji(self.application_id, name=name, image=img)
24812481
return Emoji(guild=None, state=self._connection, data=data)
24822482

24832483
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
@@ -1771,7 +1771,9 @@ def get_custom_emoji(self, guild_id: Snowflake, emoji_id: Snowflake) -> Response
17711771
)
17721772
)
17731773

1774-
def create_app_emoji(self, app_id: Snowflake, name: str, image: str) -> Response[emoji.Emoji]:
1774+
def create_app_emoji(
1775+
self, app_id: Snowflake, *, name: str, image: str
1776+
) -> Response[emoji.Emoji]:
17751777
payload: Dict[str, Any] = {
17761778
"name": name,
17771779
"image": image,
@@ -1781,7 +1783,7 @@ def create_app_emoji(self, app_id: Snowflake, name: str, image: str) -> Response
17811783
return self.request(r, json=payload)
17821784

17831785
def edit_app_emoji(
1784-
self, app_id: Snowflake, emoji_id: Snowflake, name: str
1786+
self, app_id: Snowflake, emoji_id: Snowflake, *, name: str
17851787
) -> Response[emoji.Emoji]:
17861788
payload: Dict[str, Any] = {
17871789
"name": name,

0 commit comments

Comments
 (0)