mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-06 10:02:01 +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,
|
CategoryChannel as CategoryChannelPayload,
|
||||||
GroupDMChannel as GroupChannelPayload,
|
GroupDMChannel as GroupChannelPayload,
|
||||||
ForumChannel as ForumChannelPayload,
|
ForumChannel as ForumChannelPayload,
|
||||||
|
MediaChannel as MediaChannelPayload,
|
||||||
ForumTag as ForumTagPayload,
|
ForumTag as ForumTagPayload,
|
||||||
)
|
)
|
||||||
from .types.snowflake import SnowflakeList
|
from .types.snowflake import SnowflakeList
|
||||||
@ -2202,6 +2203,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
'topic',
|
'topic',
|
||||||
'_state',
|
'_state',
|
||||||
'_flags',
|
'_flags',
|
||||||
|
'_type',
|
||||||
'nsfw',
|
'nsfw',
|
||||||
'category_id',
|
'category_id',
|
||||||
'position',
|
'position',
|
||||||
@ -2217,9 +2219,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
'_flags',
|
'_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._state: ConnectionState = state
|
||||||
self.id: int = int(data['id'])
|
self.id: int = int(data['id'])
|
||||||
|
self._type: Literal[15, 16] = data['type']
|
||||||
self._update(guild, data)
|
self._update(guild, data)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@ -2233,7 +2236,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
joined = ' '.join('%s=%r' % t for t in attrs)
|
joined = ' '.join('%s=%r' % t for t in attrs)
|
||||||
return f'<{self.__class__.__name__} {joined}>'
|
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.guild: Guild = guild
|
||||||
self.name: str = data['name']
|
self.name: str = data['name']
|
||||||
self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id')
|
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)
|
self._fill_overwrites(data)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self) -> Literal[ChannelType.forum]:
|
def type(self) -> Literal[ChannelType.forum, ChannelType.media]:
|
||||||
""":class:`ChannelType`: The channel's Discord type."""
|
""":class:`ChannelType`: The channel's Discord type."""
|
||||||
|
if self._type == 16:
|
||||||
|
return ChannelType.media
|
||||||
return ChannelType.forum
|
return ChannelType.forum
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -2356,6 +2361,13 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
""":class:`bool`: Checks if the forum is NSFW."""
|
""":class:`bool`: Checks if the forum is NSFW."""
|
||||||
return self.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)
|
@utils.copy_doc(discord.abc.GuildChannel.clone)
|
||||||
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> ForumChannel:
|
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> ForumChannel:
|
||||||
return await self._clone_impl(
|
return await self._clone_impl(
|
||||||
@ -3314,6 +3326,8 @@ def _guild_channel_factory(channel_type: int):
|
|||||||
return StageChannel, value
|
return StageChannel, value
|
||||||
elif value is ChannelType.forum:
|
elif value is ChannelType.forum:
|
||||||
return ForumChannel, value
|
return ForumChannel, value
|
||||||
|
elif value is ChannelType.media:
|
||||||
|
return ForumChannel, value
|
||||||
else:
|
else:
|
||||||
return None, value
|
return None, value
|
||||||
|
|
||||||
|
@ -202,6 +202,7 @@ class ChannelType(Enum):
|
|||||||
private_thread = 12
|
private_thread = 12
|
||||||
stage_voice = 13
|
stage_voice = 13
|
||||||
forum = 15
|
forum = 15
|
||||||
|
media = 16
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -1634,6 +1634,15 @@ class ChannelFlags(BaseFlags):
|
|||||||
"""
|
"""
|
||||||
return 1 << 4
|
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):
|
class ArrayFlags(BaseFlags):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -40,7 +40,7 @@ class PermissionOverwrite(TypedDict):
|
|||||||
deny: str
|
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]
|
ChannelType = Union[ChannelTypeWithoutThread, ThreadType]
|
||||||
|
|
||||||
|
|
||||||
@ -138,8 +138,7 @@ ForumOrderType = Literal[0, 1]
|
|||||||
ForumLayoutType = Literal[0, 1, 2]
|
ForumLayoutType = Literal[0, 1, 2]
|
||||||
|
|
||||||
|
|
||||||
class ForumChannel(_BaseTextChannel):
|
class _BaseForumChannel(_BaseTextChannel):
|
||||||
type: Literal[15]
|
|
||||||
available_tags: List[ForumTag]
|
available_tags: List[ForumTag]
|
||||||
default_reaction_emoji: Optional[DefaultReaction]
|
default_reaction_emoji: Optional[DefaultReaction]
|
||||||
default_sort_order: Optional[ForumOrderType]
|
default_sort_order: Optional[ForumOrderType]
|
||||||
@ -147,7 +146,17 @@ class ForumChannel(_BaseTextChannel):
|
|||||||
flags: NotRequired[int]
|
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):
|
class _BaseDMChannel(_BaseChannel):
|
||||||
|
@ -1513,6 +1513,12 @@ of :class:`enum.Enum`.
|
|||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
|
.. attribute:: media
|
||||||
|
|
||||||
|
A media channel.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
|
||||||
.. class:: MessageType
|
.. class:: MessageType
|
||||||
|
|
||||||
Specifies the type of :class:`Message`. This is used to denote if a message
|
Specifies the type of :class:`Message`. This is used to denote if a message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user