Browse Source

Change ForumTag.emoji to be optional

pull/8429/head
Rapptz 3 years ago
parent
commit
fdebe069a6
  1. 20
      discord/channel.py

20
discord/channel.py

@ -2006,18 +2006,18 @@ class ForumTag(Hashable):
moderated: :class:`bool` moderated: :class:`bool`
Whether this tag can only be added or removed by a moderator with Whether this tag can only be added or removed by a moderator with
the :attr:`~Permissions.manage_threads` permission. the :attr:`~Permissions.manage_threads` permission.
emoji: :class:`PartialEmoji` emoji: Optional[:class:`PartialEmoji`]
The emoji that is used to represent this tag. The emoji that is used to represent this tag.
Note that if the emoji is a custom emoji, it will *not* have name information. Note that if the emoji is a custom emoji, it will *not* have name information.
""" """
__slots__ = ('name', 'id', 'moderated', 'emoji') __slots__ = ('name', 'id', 'moderated', 'emoji')
def __init__(self, *, name: str, emoji: EmojiInputType, moderated: bool = False) -> None: def __init__(self, *, name: str, emoji: Optional[EmojiInputType], moderated: bool = False) -> None:
self.name: str = name self.name: str = name
self.id: int = 0 self.id: int = 0
self.moderated: bool = moderated self.moderated: bool = moderated
self.emoji: PartialEmoji self.emoji: Optional[PartialEmoji] = None
if isinstance(emoji, _EmojiTag): if isinstance(emoji, _EmojiTag):
self.emoji = emoji._to_partial() self.emoji = emoji._to_partial()
elif isinstance(emoji, str): elif isinstance(emoji, str):
@ -2034,7 +2034,10 @@ class ForumTag(Hashable):
emoji_name = data['emoji_name'] or '' emoji_name = data['emoji_name'] or ''
emoji_id = utils._get_as_snowflake(data, 'emoji_id') or None # Coerce 0 -> None emoji_id = utils._get_as_snowflake(data, 'emoji_id') or None # Coerce 0 -> None
self.emoji = PartialEmoji.with_state(state=state, name=emoji_name, id=emoji_id) if not emoji_name and not emoji_id:
self.emoji = None
else:
self.emoji = PartialEmoji.with_state(state=state, name=emoji_name, id=emoji_id)
return self return self
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> Dict[str, Any]:
@ -2042,7 +2045,10 @@ class ForumTag(Hashable):
'name': self.name, 'name': self.name,
'moderated': self.moderated, 'moderated': self.moderated,
} }
payload.update(self.emoji._to_forum_tag_payload()) if self.emoji is not None:
payload.update(self.emoji._to_forum_tag_payload())
else:
payload.update(emoji_id=None, emoji_name=None)
if self.id: if self.id:
payload['id'] = self.id payload['id'] = self.id
@ -2393,7 +2399,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
self, self,
*, *,
name: str, name: str,
emoji: PartialEmoji, emoji: Optional[PartialEmoji] = None,
moderated: bool = False, moderated: bool = False,
reason: Optional[str] = None, reason: Optional[str] = None,
) -> ForumTag: ) -> ForumTag:
@ -2408,7 +2414,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
---------- ----------
name: :class:`str` name: :class:`str`
The name of the tag. Can only be up to 20 characters. The name of the tag. Can only be up to 20 characters.
emoji: Union[:class:`str`, :class:`PartialEmoji`] emoji: Optional[Union[:class:`str`, :class:`PartialEmoji`]]
The emoji to use for the tag. The emoji to use for the tag.
moderated: :class:`bool` moderated: :class:`bool`
Whether the tag can only be applied by moderators. Whether the tag can only be applied by moderators.

Loading…
Cancel
Save