Browse Source

Allow creating a news channel in create_text_channel

pull/10109/head
Rapptz 3 years ago
committed by dolfies
parent
commit
30be0372ef
  1. 5
      discord/channel.py
  2. 16
      discord/guild.py

5
discord/channel.py

@ -86,6 +86,7 @@ if TYPE_CHECKING:
from .settings import ChannelSettings
from .types.channel import (
TextChannel as TextChannelPayload,
NewsChannel as NewsChannelPayload,
VoiceChannel as VoiceChannelPayload,
StageChannel as StageChannelPayload,
DMChannel as DMChannelPayload,
@ -165,7 +166,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: int = data['type']
@ -183,7 +184,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')

16
discord/guild.py

@ -1175,11 +1175,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
@ -1232,6 +1232,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,
@ -1303,6 +1304,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).
@ -1342,7 +1347,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…
Cancel
Save