aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-07-28 23:46:47 -0400
committerRapptz <[email protected]>2021-07-28 23:50:02 -0400
commitdac0267e28ecaef1ba0b25eda25c1ef073ecaeb0 (patch)
treef70f0b50299998fd81f20034b7719f2176239723
parentUse a default value for StageInstance.discoverable_enabled (diff)
downloaddiscord.py-dac0267e28ecaef1ba0b25eda25c1ef073ecaeb0.tar.xz
discord.py-dac0267e28ecaef1ba0b25eda25c1ef073ecaeb0.zip
Allow creating a public thread without a starter message
-rw-r--r--discord/channel.py19
-rw-r--r--discord/http.py6
-rw-r--r--discord/message.py3
3 files changed, 17 insertions, 11 deletions
diff --git a/discord/channel.py b/discord/channel.py
index d5a18a70..1ac05c65 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -637,6 +637,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
name: str,
message: Optional[Snowflake] = None,
auto_archive_duration: ThreadArchiveDuration = 1440,
+ type: Optional[ChannelType] = None,
reason: Optional[str] = None
) -> Thread:
"""|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
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
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`
The duration in minutes before a thread is automatically archived for inactivity.
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`
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
"""
+ if type is None:
+ type = ChannelType.private_thread
+
if message is None:
- data = await self._state.http.start_private_thread(
+ data = await self._state.http.start_thread_without_message(
self.id,
name=name,
auto_archive_duration=auto_archive_duration,
- type=ChannelType.private_thread.value,
+ type=type.value,
reason=reason,
)
else:
- data = await self._state.http.start_public_thread(
+ data = await self._state.http.start_thread_with_message(
self.id,
message.id,
name=name,
auto_archive_duration=auto_archive_duration,
- type=ChannelType.public_thread.value,
reason=reason,
)
diff --git a/discord/http.py b/discord/http.py
index 86a9e094..fd0f1e78 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -867,20 +867,18 @@ class HTTPClient:
# Thread management
- def start_public_thread(
+ def start_thread_with_message(
self,
channel_id: Snowflake,
message_id: Snowflake,
*,
name: str,
auto_archive_duration: threads.ThreadArchiveDuration,
- type: threads.ThreadType,
reason: Optional[str] = None,
) -> Response[threads.Thread]:
payload = {
'name': name,
'auto_archive_duration': auto_archive_duration,
- 'type': type,
}
route = Route(
@@ -888,7 +886,7 @@ class HTTPClient:
)
return self.request(route, json=payload, reason=reason)
- def start_private_thread(
+ def start_thread_without_message(
self,
channel_id: Snowflake,
*,
diff --git a/discord/message.py b/discord/message.py
index 18c4658e..82f812db 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -1511,12 +1511,11 @@ class Message(Hashable):
if self.guild is None:
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.id,
name=name,
auto_archive_duration=auto_archive_duration,
- type=ChannelType.public_thread.value,
)
return Thread(guild=self.guild, state=self._state, data=data) # type: ignore