mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-15 10:19:59 +00:00
Allow creating a news channel in create_text_channel
This commit is contained in:
parent
20a7961e19
commit
0851e03f00
discord
@ -85,6 +85,7 @@ if TYPE_CHECKING:
|
||||
from .ui.view import View
|
||||
from .types.channel import (
|
||||
TextChannel as TextChannelPayload,
|
||||
NewsChannel as NewsChannelPayload,
|
||||
VoiceChannel as VoiceChannelPayload,
|
||||
StageChannel as StageChannelPayload,
|
||||
DMChannel as DMChannelPayload,
|
||||
@ -163,7 +164,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
||||
'default_auto_archive_duration',
|
||||
)
|
||||
|
||||
def __init__(self, *, state: ConnectionState, guild: Guild, data: TextChannelPayload):
|
||||
def __init__(self, *, state: ConnectionState, guild: Guild, data: Union[TextChannelPayload, NewsChannelPayload]):
|
||||
self._state: ConnectionState = state
|
||||
self.id: int = int(data['id'])
|
||||
self._type: Literal[0, 5] = data['type']
|
||||
@ -181,7 +182,7 @@ class TextChannel(discord.abc.Messageable, 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: TextChannelPayload) -> None:
|
||||
def _update(self, guild: Guild, data: Union[TextChannelPayload, NewsChannelPayload]) -> None:
|
||||
self.guild: Guild = guild
|
||||
self.name: str = data['name']
|
||||
self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id')
|
||||
|
@ -1127,11 +1127,11 @@ class Guild(Hashable):
|
||||
def _create_channel(
|
||||
self,
|
||||
name: str,
|
||||
channel_type: Literal[ChannelType.text],
|
||||
channel_type: Literal[ChannelType.news, ChannelType.text],
|
||||
overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ...,
|
||||
category: Optional[Snowflake] = ...,
|
||||
**options: Any,
|
||||
) -> Coroutine[Any, Any, GuildChannelPayload]:
|
||||
) -> Coroutine[Any, Any, Union[TextChannelPayload, NewsChannelPayload]]:
|
||||
...
|
||||
|
||||
@overload
|
||||
@ -1184,6 +1184,7 @@ class Guild(Hashable):
|
||||
*,
|
||||
reason: Optional[str] = None,
|
||||
category: Optional[CategoryChannel] = None,
|
||||
news: bool = False,
|
||||
position: int = MISSING,
|
||||
topic: str = MISSING,
|
||||
slowmode_delay: int = MISSING,
|
||||
@ -1255,6 +1256,10 @@ class Guild(Hashable):
|
||||
The maximum value possible is `21600`.
|
||||
nsfw: :class:`bool`
|
||||
To mark the channel as NSFW or not.
|
||||
news: :class:`bool`
|
||||
Whether to create the text channel as a news channel.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
default_auto_archive_duration: :class:`int`
|
||||
The default auto archive duration for threads created in the text channel (in minutes).
|
||||
|
||||
@ -1294,7 +1299,12 @@ class Guild(Hashable):
|
||||
options["default_auto_archive_duration"] = default_auto_archive_duration
|
||||
|
||||
data = await self._create_channel(
|
||||
name, overwrites=overwrites, channel_type=ChannelType.text, category=category, reason=reason, **options
|
||||
name,
|
||||
overwrites=overwrites,
|
||||
channel_type=ChannelType.news if news else ChannelType.text,
|
||||
category=category,
|
||||
reason=reason,
|
||||
**options,
|
||||
)
|
||||
channel = TextChannel(state=self._state, guild=self, data=data)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user