Browse Source

Add default_reaction_emoji and default_forum_layout to create_forum

pull/9301/head
Puncher 2 years ago
committed by GitHub
parent
commit
7db197ef25
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      discord/guild.py
  2. 2
      discord/http.py

36
discord/guild.py

@ -74,6 +74,7 @@ from .enums import (
Locale,
AutoModRuleEventType,
ForumOrderType,
ForumLayoutType,
)
from .mixins import Hashable
from .user import User
@ -91,6 +92,7 @@ from .audit_logs import AuditLogEntry
from .object import OLDEST_OBJECT, Object
from .welcome_screen import WelcomeScreen, WelcomeChannel
from .automod import AutoModRule, AutoModTrigger, AutoModRuleAction
from .partial_emoji import _EmojiTag, PartialEmoji
__all__ = (
@ -130,6 +132,7 @@ if TYPE_CHECKING:
from .types.integration import IntegrationType
from .types.snowflake import SnowflakeList
from .types.widget import EditWidgetSettings
from .message import EmojiInputType
VocalGuildChannel = Union[VoiceChannel, StageChannel]
GuildChannel = Union[VocalGuildChannel, ForumChannel, TextChannel, CategoryChannel]
@ -1605,7 +1608,9 @@ class Guild(Hashable):
reason: Optional[str] = None,
default_auto_archive_duration: int = MISSING,
default_thread_slowmode_delay: int = MISSING,
default_sort_order: Optional[ForumOrderType] = None,
default_sort_order: Optional[ForumOrderType] = MISSING,
default_reaction_emoji: Optional[EmojiInputType] = MISSING,
default_layout: Optional[ForumLayoutType] = MISSING,
available_tags: Sequence[ForumTag] = MISSING,
) -> ForumChannel:
"""|coro|
@ -1653,6 +1658,15 @@ class Guild(Hashable):
default_sort_order: Optional[:class:`ForumOrderType`]
The default sort order for posts in this forum channel.
.. versionadded:: 2.3
default_reaction_emoji: Optional[Union[:class:`Emoji`, :class:`PartialEmoji`, :class:`str`]]
The default reaction emoji for threads created in this forum to show in the
add reaction button.
.. versionadded:: 2.3
default_layout: Optional[:class:`ForumLayoutType`]
The default layout for posts in this forum.
.. versionadded:: 2.3
available_tags: Sequence[:class:`ForumTag`]
The available tags for this forum channel.
@ -1693,9 +1707,7 @@ class Guild(Hashable):
if default_thread_slowmode_delay is not MISSING:
options['default_thread_rate_limit_per_user'] = default_thread_slowmode_delay
if default_sort_order is None:
options['default_sort_order'] = None
else:
if default_sort_order not in (MISSING, None):
if not isinstance(default_sort_order, ForumOrderType):
raise TypeError(
f'default_sort_order parameter must be a ForumOrderType not {default_sort_order.__class__.__name__}'
@ -1703,6 +1715,22 @@ class Guild(Hashable):
options['default_sort_order'] = default_sort_order.value
if default_reaction_emoji not in (MISSING, None):
if isinstance(default_reaction_emoji, _EmojiTag):
options['default_reaction_emoji'] = default_reaction_emoji._to_partial()._to_forum_tag_payload()
elif isinstance(default_reaction_emoji, str):
options['default_reaction_emoji'] = PartialEmoji.from_str(default_reaction_emoji)._to_forum_tag_payload()
else:
raise ValueError(f'default_reaction_emoji parameter must be either Emoji, PartialEmoji, or str')
if default_layout not in (MISSING, None):
if not isinstance(default_layout, ForumLayoutType):
raise TypeError(
f'default_layout parameter must be a ForumLayoutType not {default_layout.__class__.__name__}'
)
options['default_forum_layout'] = default_layout.value
if available_tags is not MISSING:
options['available_tags'] = [t.to_dict() for t in available_tags]

2
discord/http.py

@ -1191,6 +1191,8 @@ class HTTPClient:
'default_auto_archive_duration',
'default_thread_rate_limit_per_user',
'default_sort_order',
'default_reaction_emoji',
'default_forum_layout',
'available_tags',
)
payload.update({k: v for k, v in options.items() if k in valid_keys and v is not None})

Loading…
Cancel
Save