mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 08:44:10 +00:00
Add support for media channels
This commit is contained in:
parent
ca5cbcbdf3
commit
e6a0dc5bc0
@ -98,6 +98,7 @@ if TYPE_CHECKING:
|
||||
CategoryChannel as CategoryChannelPayload,
|
||||
GroupDMChannel as GroupChannelPayload,
|
||||
ForumChannel as ForumChannelPayload,
|
||||
MediaChannel as MediaChannelPayload,
|
||||
ForumTag as ForumTagPayload,
|
||||
)
|
||||
from .types.snowflake import SnowflakeList
|
||||
@ -2202,6 +2203,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
||||
'topic',
|
||||
'_state',
|
||||
'_flags',
|
||||
'_type',
|
||||
'nsfw',
|
||||
'category_id',
|
||||
'position',
|
||||
@ -2217,9 +2219,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:
|
||||
@ -2233,7 +2236,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')
|
||||
@ -2267,8 +2270,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
||||
self._fill_overwrites(data)
|
||||
|
||||
@property
|
||||
def type(self) -> Literal[ChannelType.forum]:
|
||||
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
|
||||
@ -2356,6 +2361,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(
|
||||
@ -3314,6 +3326,8 @@ def _guild_channel_factory(channel_type: int):
|
||||
return StageChannel, value
|
||||
elif value is ChannelType.forum:
|
||||
return ForumChannel, value
|
||||
elif value is ChannelType.media:
|
||||
return ForumChannel, value
|
||||
else:
|
||||
return None, value
|
||||
|
||||
|
@ -202,6 +202,7 @@ class ChannelType(Enum):
|
||||
private_thread = 12
|
||||
stage_voice = 13
|
||||
forum = 15
|
||||
media = 16
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
@ -1634,6 +1634,15 @@ class ChannelFlags(BaseFlags):
|
||||
"""
|
||||
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
|
||||
|
||||
|
||||
class ArrayFlags(BaseFlags):
|
||||
@classmethod
|
||||
|
@ -40,7 +40,7 @@ class PermissionOverwrite(TypedDict):
|
||||
deny: str
|
||||
|
||||
|
||||
ChannelTypeWithoutThread = Literal[0, 1, 2, 3, 4, 5, 6, 13, 15]
|
||||
ChannelTypeWithoutThread = Literal[0, 1, 2, 3, 4, 5, 6, 13, 15, 16]
|
||||
ChannelType = Union[ChannelTypeWithoutThread, ThreadType]
|
||||
|
||||
|
||||
@ -138,8 +138,7 @@ 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]
|
||||
@ -147,7 +146,17 @@ class ForumChannel(_BaseTextChannel):
|
||||
flags: NotRequired[int]
|
||||
|
||||
|
||||
GuildChannel = Union[TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StageChannel, ThreadChannel, ForumChannel]
|
||||
class ForumChannel(_BaseForumChannel):
|
||||
type: Literal[15]
|
||||
|
||||
|
||||
class MediaChannel(_BaseForumChannel):
|
||||
type: Literal[16]
|
||||
|
||||
|
||||
GuildChannel = Union[
|
||||
TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StageChannel, ThreadChannel, ForumChannel, MediaChannel
|
||||
]
|
||||
|
||||
|
||||
class _BaseDMChannel(_BaseChannel):
|
||||
|
@ -1513,6 +1513,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user