diff --git a/discord/channel.py b/discord/channel.py index bdb1be07d..8aab1f116 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -116,6 +116,7 @@ if TYPE_CHECKING: CategoryChannel as CategoryChannelPayload, GroupDMChannel as GroupChannelPayload, ForumChannel as ForumChannelPayload, + MediaChannel as MediaChannelPayload, ForumTag as ForumTagPayload, ) from .types.oauth2 import WebhookChannel as WebhookChannelPayload @@ -2432,6 +2433,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable): 'topic', '_state', '_flags', + '_type', 'nsfw', 'category_id', 'position', @@ -2447,9 +2449,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable): '_flags', ) - def __init__(self, *, state: ConnectionState, guild: Guild, data: ForumChannelPayload): + def __init__(self, *, state: ConnectionState, guild: Guild, data: Union[ForumChannelPayload, MediaChannelPayload]): self._state: ConnectionState = state self.id: int = int(data['id']) + self._type: Literal[15, 16] = data['type'] self._update(guild, data) def __repr__(self) -> str: @@ -2463,7 +2466,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable): joined = ' '.join('%s=%r' % t for t in attrs) return f'<{self.__class__.__name__} {joined}>' - def _update(self, guild: Guild, data: ForumChannelPayload) -> None: + def _update(self, guild: Guild, data: Union[ForumChannelPayload, MediaChannelPayload]) -> None: self.guild: Guild = guild self.name: str = data['name'] self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id') @@ -2499,8 +2502,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable): self._fill_overwrites(data) @property - def type(self) -> ChannelType: + def type(self) -> Literal[ChannelType.forum, ChannelType.media]: """:class:`ChannelType`: The channel's Discord type.""" + if self._type == 16: + return ChannelType.media return ChannelType.forum @property @@ -2574,6 +2579,13 @@ class ForumChannel(discord.abc.GuildChannel, Hashable): """:class:`bool`: Checks if the forum is NSFW.""" return self.nsfw + def is_media(self) -> bool: + """:class:`bool`: Checks if the channel is a media channel. + + .. versionadded:: 2.4 + """ + return self._type == ChannelType.media.value + @utils.copy_doc(discord.abc.GuildChannel.clone) async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> ForumChannel: return await self._clone_impl( @@ -4521,6 +4533,8 @@ def _guild_channel_factory(channel_type: int): return DirectoryChannel, value elif value is ChannelType.forum: return ForumChannel, value + elif value is ChannelType.media: + return ForumChannel, value else: return None, value diff --git a/discord/enums.py b/discord/enums.py index f6b5b6b48..82b06eebc 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -263,6 +263,7 @@ class ChannelType(Enum): stage_voice = 13 directory = 14 forum = 15 + media = 16 def __str__(self) -> str: return self.name diff --git a/discord/flags.py b/discord/flags.py index dc0508a0a..99237cc23 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1445,6 +1445,15 @@ class ChannelFlags(BaseFlags): """:class:`bool`: Returns ``True`` if a tag is required to be specified when creating a thread in a :class:`ForumChannel`.""" return 1 << 4 + @flag_value + def hide_media_download_options(self): + """:class:`bool`: Returns ``True`` if the client hides embedded media download options in a :class:`ForumChannel`. + Only available in media channels. + + .. versionadded:: 2.4 + """ + return 1 << 15 + @fill_with_flags() class PaymentSourceFlags(BaseFlags): diff --git a/discord/types/channel.py b/discord/types/channel.py index dd36980c1..0219cac71 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -41,7 +41,7 @@ class PermissionOverwrite(TypedDict): deny: str -ChannelTypeWithoutThread = Literal[0, 1, 2, 3, 4, 5, 6, 13, 14, 15] +ChannelTypeWithoutThread = Literal[0, 1, 2, 3, 4, 5, 6, 13, 14, 15, 16] ChannelType = Union[ChannelTypeWithoutThread, ThreadType] @@ -154,16 +154,28 @@ ForumOrderType = Literal[0, 1] ForumLayoutType = Literal[0, 1, 2] -class ForumChannel(_BaseTextChannel): - type: Literal[15] +class _BaseForumChannel(_BaseTextChannel): available_tags: List[ForumTag] default_reaction_emoji: Optional[DefaultReaction] default_sort_order: Optional[ForumOrderType] default_forum_layout: NotRequired[ForumLayoutType] +<<<<<<< HEAD GuildChannel = Union[ TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StageChannel, DirectoryChannel, ThreadChannel, ForumChannel +======= +class ForumChannel(_BaseForumChannel): + type: Literal[15] + + +class MediaChannel(_BaseForumChannel): + type: Literal[16] + + +GuildChannel = Union[ + TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StageChannel, ThreadChannel, ForumChannel, MediaChannel +>>>>>>> e6a0dc5b (Add support for media channels) ] diff --git a/docs/api.rst b/docs/api.rst index 694c0a49a..938e31a86 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1738,6 +1738,12 @@ of :class:`enum.Enum`. .. versionadded:: 2.0 + .. attribute:: media + + A media channel. + + .. versionadded:: 2.4 + .. class:: MessageType Specifies the type of :class:`Message`. This is used to denote if a message