Skip to content

Commit 55efab4

Browse files
LumabotsLulalaby
andauthored
feat: Add mention property to BaseEmoji class (#2972)
* Add mention property to BaseEmoji class Introduces a mention property to BaseEmoji, providing a formatted string for mentioning emojis in messages. Also fixes formatting in AppEmoji's __repr__ method. * chore: changelog --------- Co-authored-by: Lala Sabathil <[email protected]>
1 parent 34595ac commit 55efab4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ These changes are available on the `master` branch, but have not yet been releas
4444
- Added support for Guild Incidents via `Guild.incidents_data` and
4545
`Guild.modify_incident_actions()`.
4646
([#2955](https://github.com/Pycord-Development/pycord/pull/2955))
47+
- Added `mention` property to `BaseEmoji`.
48+
([#2972](https://github.com/Pycord-Development/pycord/pull/2972))
4749

4850
### Changed
4951

@@ -92,6 +94,8 @@ These changes are available on the `master` branch, but have not yet been releas
9294
- Fixed attributes like :attr:`Member.display_banner` being `None` when the member has
9395
no guild specific banner, but does have a global one.
9496
([#2968](https://github.com/Pycord-Development/pycord/pull/2949))
97+
- Fixed `__repr__` formatting for `AppEmoji`.
98+
([#2972](https://github.com/Pycord-Development/pycord/pull/2972))
9599

96100
### Deprecated
97101

discord/emoji.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050

5151
class BaseEmoji(_EmojiTag, AssetMixin):
52-
5352
__slots__: tuple[str, ...] = (
5453
"require_colons",
5554
"animated",
@@ -110,6 +109,13 @@ def url(self) -> str:
110109
fmt = "gif" if self.animated else "png"
111110
return f"{Asset.BASE}/emojis/{self.id}.{fmt}"
112111

112+
@property
113+
def mention(self) -> str:
114+
"""Return a string that allows you to mention the emoji in a message."""
115+
if self.animated:
116+
return f"<a:{self.name}:{self.id}>"
117+
return f"<:{self.name}:{self.id}>"
118+
113119

114120
class GuildEmoji(BaseEmoji):
115121
"""Represents a custom emoji in a guild.
@@ -345,7 +351,7 @@ def __init__(
345351
super().__init__(state=state, data=data)
346352

347353
def __repr__(self) -> str:
348-
return "<AppEmoji" f" id={self.id} name={self.name!r} animated={self.animated}>"
354+
return f"<AppEmoji id={self.id} name={self.name!r} animated={self.animated}>"
349355

350356
@property
351357
def guild(self) -> Guild:

0 commit comments

Comments
 (0)