diff --git a/CHANGELOG.md b/CHANGELOG.md index 37fea1dc96..5173e5795c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#3235](https://github.com/Pycord-Development/pycord/pull/3235)) - Include `bypass_slowmode` in `Permissions.all`. ([#3231](https://github.com/Pycord-Development/pycord/pull/3231)) +- Allow `ForumTag` to be created without an emoji. + ([#3245](https://github.com/Pycord-Development/pycord/pull/3245)) ### Deprecated diff --git a/discord/channel.py b/discord/channel.py index 2a6d5182ac..7cb6fa2698 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -147,27 +147,27 @@ class ForumTag(Hashable): moderated: :class:`bool` Whether this tag can only be added or removed by a moderator with the :attr:`~Permissions.manage_threads` permission. - emoji: :class:`PartialEmoji` - The emoji that is used to represent this tag. + emoji: Optional[:class:`PartialEmoji`] + The emoji that is used to represent this tag. Defaults to ``None``. Note that if the emoji is a custom emoji, it will *not* have name information. """ __slots__ = ("name", "id", "moderated", "emoji") def __init__( - self, *, name: str, emoji: EmojiInputType, moderated: bool = False + self, *, name: str, emoji: EmojiInputType | None = None, moderated: bool = False ) -> None: self.name: str = name self.id: int = 0 self.moderated: bool = moderated - self.emoji: PartialEmoji + self.emoji: PartialEmoji | None = None if isinstance(emoji, _EmojiTag): self.emoji = emoji._to_partial() elif isinstance(emoji, str): self.emoji = PartialEmoji.from_str(emoji) - else: + elif emoji is not None: raise TypeError( - "emoji must be a GuildEmoji, PartialEmoji, or str and not" + "emoji must be a GuildEmoji, PartialEmoji, str, or None and not" f" {emoji.__class__!r}" ) @@ -189,14 +189,22 @@ def from_data(cls, *, state: ConnectionState, data: ForumTagPayload) -> ForumTag emoji_name = data["emoji_name"] or "" emoji_id = utils._get_as_snowflake(data, "emoji_id") or None - self.emoji = PartialEmoji.with_state(state=state, name=emoji_name, id=emoji_id) + self.emoji = None + if emoji_name or emoji_id: + self.emoji = PartialEmoji.with_state( + state=state, name=emoji_name, id=emoji_id + ) return self def to_dict(self) -> dict[str, Any]: payload: dict[str, Any] = { "name": self.name, "moderated": self.moderated, - } | self.emoji._to_forum_reaction_payload() + "emoji_id": None, + "emoji_name": None, + } + if self.emoji is not None: + payload.update(self.emoji._to_forum_reaction_payload()) if self.id: payload["id"] = self.id