Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 16 additions & 8 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Comment thread
Paillat-dev marked this conversation as resolved.
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}"
)

Expand All @@ -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
Expand Down
Loading