Allow creating a public thread without a starter message
This commit is contained in:
parent
13251da8ce
commit
dac0267e28
@ -637,6 +637,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
name: str,
|
name: str,
|
||||||
message: Optional[Snowflake] = None,
|
message: Optional[Snowflake] = None,
|
||||||
auto_archive_duration: ThreadArchiveDuration = 1440,
|
auto_archive_duration: ThreadArchiveDuration = 1440,
|
||||||
|
type: Optional[ChannelType] = None,
|
||||||
reason: Optional[str] = None
|
reason: Optional[str] = None
|
||||||
) -> Thread:
|
) -> Thread:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
@ -645,7 +646,9 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
|
|
||||||
If no starter message is passed with the ``message`` parameter then
|
If no starter message is passed with the ``message`` parameter then
|
||||||
you must have :attr:`~discord.Permissions.send_messages` and
|
you must have :attr:`~discord.Permissions.send_messages` and
|
||||||
:attr:`~discord.Permissions.use_private_threads` in order to start the thread.
|
:attr:`~discord.Permissions.use_private_threads` in order to start the thread
|
||||||
|
if the ``type`` parameter is :attr:`~discord.ChannelType.private_thread`.
|
||||||
|
Otherwise :attr:`~discord.Permissions.use_public_threads` is needed.
|
||||||
|
|
||||||
If a starter message is passed with the ``message`` parameter then
|
If a starter message is passed with the ``message`` parameter then
|
||||||
you must have :attr:`~discord.Permissions.send_messages` and
|
you must have :attr:`~discord.Permissions.send_messages` and
|
||||||
@ -664,6 +667,10 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
auto_archive_duration: :class:`int`
|
auto_archive_duration: :class:`int`
|
||||||
The duration in minutes before a thread is automatically archived for inactivity.
|
The duration in minutes before a thread is automatically archived for inactivity.
|
||||||
Defaults to ``1440`` or 24 hours.
|
Defaults to ``1440`` or 24 hours.
|
||||||
|
type: Optional[:class:`ChannelType`]
|
||||||
|
The type of thread to create. If a ``message`` is passed then this parameter
|
||||||
|
is ignored, as a thread started with a message is always a public thread.
|
||||||
|
By default this creates a private thread if this is ``None``.
|
||||||
reason: :class:`str`
|
reason: :class:`str`
|
||||||
The reason for starting a new thread. Shows up on the audit log.
|
The reason for starting a new thread. Shows up on the audit log.
|
||||||
|
|
||||||
@ -680,21 +687,23 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
The started thread
|
The started thread
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if type is None:
|
||||||
|
type = ChannelType.private_thread
|
||||||
|
|
||||||
if message is None:
|
if message is None:
|
||||||
data = await self._state.http.start_private_thread(
|
data = await self._state.http.start_thread_without_message(
|
||||||
self.id,
|
self.id,
|
||||||
name=name,
|
name=name,
|
||||||
auto_archive_duration=auto_archive_duration,
|
auto_archive_duration=auto_archive_duration,
|
||||||
type=ChannelType.private_thread.value,
|
type=type.value,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
data = await self._state.http.start_public_thread(
|
data = await self._state.http.start_thread_with_message(
|
||||||
self.id,
|
self.id,
|
||||||
message.id,
|
message.id,
|
||||||
name=name,
|
name=name,
|
||||||
auto_archive_duration=auto_archive_duration,
|
auto_archive_duration=auto_archive_duration,
|
||||||
type=ChannelType.public_thread.value,
|
|
||||||
reason=reason,
|
reason=reason,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -867,20 +867,18 @@ class HTTPClient:
|
|||||||
|
|
||||||
# Thread management
|
# Thread management
|
||||||
|
|
||||||
def start_public_thread(
|
def start_thread_with_message(
|
||||||
self,
|
self,
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
*,
|
*,
|
||||||
name: str,
|
name: str,
|
||||||
auto_archive_duration: threads.ThreadArchiveDuration,
|
auto_archive_duration: threads.ThreadArchiveDuration,
|
||||||
type: threads.ThreadType,
|
|
||||||
reason: Optional[str] = None,
|
reason: Optional[str] = None,
|
||||||
) -> Response[threads.Thread]:
|
) -> Response[threads.Thread]:
|
||||||
payload = {
|
payload = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'auto_archive_duration': auto_archive_duration,
|
'auto_archive_duration': auto_archive_duration,
|
||||||
'type': type,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
route = Route(
|
route = Route(
|
||||||
@ -888,7 +886,7 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(route, json=payload, reason=reason)
|
return self.request(route, json=payload, reason=reason)
|
||||||
|
|
||||||
def start_private_thread(
|
def start_thread_without_message(
|
||||||
self,
|
self,
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
*,
|
*,
|
||||||
|
@ -1511,12 +1511,11 @@ class Message(Hashable):
|
|||||||
if self.guild is None:
|
if self.guild is None:
|
||||||
raise InvalidArgument('This message does not have guild info attached.')
|
raise InvalidArgument('This message does not have guild info attached.')
|
||||||
|
|
||||||
data = await self._state.http.start_public_thread(
|
data = await self._state.http.start_thread_with_message(
|
||||||
self.channel.id,
|
self.channel.id,
|
||||||
self.id,
|
self.id,
|
||||||
name=name,
|
name=name,
|
||||||
auto_archive_duration=auto_archive_duration,
|
auto_archive_duration=auto_archive_duration,
|
||||||
type=ChannelType.public_thread.value,
|
|
||||||
)
|
)
|
||||||
return Thread(guild=self.guild, state=self._state, data=data) # type: ignore
|
return Thread(guild=self.guild, state=self._state, data=data) # type: ignore
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user