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`
Whether this tag can only be added or removed by a moderator with
the :attr:`~Permissions.manage_threads` permission.
emoji: :class:`PartialEmoji`
emoji: Optional[:class:`PartialEmoji`]
The emoji that is used to represent this tag.
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) -> None:
def __init__(self, *, name: str, emoji: Optional[EmojiInputType], moderated: bool = False) -> None:
self.name: str = name
self.id: int = 0
self.moderated: bool = moderated
self.emoji: PartialEmoji
self.emoji: Optional[PartialEmoji] = None
if isinstance(emoji, _EmojiTag):
self.emoji = emoji._to_partial()
elif isinstance(emoji, str):
@ -2034,7 +2034,10 @@ class ForumTag(Hashable):
emoji_name = data['emoji_name'] or ''
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
def to_dict(self) -> Dict[str, Any]:
@ -2042,7 +2045,10 @@ class ForumTag(Hashable):
'name': self.name,
'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:
payload['id'] = self.id
@ -2393,7 +2399,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
self,
*,
name: str,
emoji: PartialEmoji,
emoji: Optional[PartialEmoji] = None,
moderated: bool = False,
reason: Optional[str] = None,
) -> ForumTag:
@ -2408,7 +2414,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
----------
name: :class:`str`
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.
moderated: :class:`bool`
Whether the tag can only be applied by moderators.

Loading…
Cancel
Save