Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread attribute to Message class #850

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ class Message(Hashable):
channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`, :class:`GroupChannel`, :class:`PartialMessageable`]
The :class:`TextChannel` or :class:`Thread` that the message was sent from.
Could be a :class:`DMChannel` or :class:`GroupChannel` if it's a private message.
thread: Optional[:class:`Thread`]
The thread created from this message, if any.

.. versionadded:: 2.0
Dorukyum marked this conversation as resolved.
Show resolved Hide resolved
reference: Optional[:class:`~discord.MessageReference`]
The message that this message references. This is only applicable to messages of
type :attr:`MessageType.pins_add`, crossposted messages created by a
Expand Down Expand Up @@ -691,6 +695,7 @@ class Message(Hashable):
"components",
"guild",
"interaction",
"thread",
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -766,6 +771,12 @@ def __init__(
except KeyError:
self.interaction = None

self.thread: Optional[Thread]
try:
self.thread = Thread(guild=self.guild, state=state, data=data["thread"])
except KeyError:
self.thread = None

for handler in ("author", "member", "mentions", "mention_roles"):
try:
getattr(self, f"_handle_{handler}")(data[handler])
Expand Down Expand Up @@ -1608,7 +1619,8 @@ async def create_thread(self, *, name: str, auto_archive_duration: ThreadArchive
name=name,
auto_archive_duration=auto_archive_duration or default_auto_archive_duration,
)
return Thread(guild=self.guild, state=self._state, data=data)
self.thread = Thread(guild=self.guild, state=self._state, data=data)
return self.thread

async def reply(self, content: Optional[str] = None, **kwargs) -> Message:
"""|coro|
Expand Down
2 changes: 2 additions & 0 deletions discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import TYPE_CHECKING, List, Literal, Optional, TypedDict, Union

from .channel import ChannelType
from .threads import Thread
from .components import Component
from .embed import Embed
from .emoji import PartialEmoji
Expand Down Expand Up @@ -130,6 +131,7 @@ class Message(_MessageOptional):
embeds: List[Embed]
pinned: bool
type: MessageType
thread: Thread


AllowedMentionType = Literal["roles", "users", "everyone"]
Expand Down