Thread
attrs
class
ThreadMember (DiscordObject, SendMixin)
¶
A thread member is used to indicate whether a user has joined a thread or not.
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
join_timestamp |
Timestamp |
The time the current user last joined the thread. |
flags |
int |
Any user-thread settings, currently only used for notifications. |
Source code in naff/models/discord/thread.py
@define()
class ThreadMember(DiscordObject, SendMixin):
"""A thread member is used to indicate whether a user has joined a thread or not."""
join_timestamp: Timestamp = field(converter=timestamp_converter)
"""The time the current user last joined the thread."""
flags: int = field()
"""Any user-thread settings, currently only used for notifications."""
_user_id: "Snowflake_Type" = field(converter=optional(to_snowflake))
async def fetch_thread(self) -> "TYPE_THREAD_CHANNEL":
"""
Fetches the thread associated with with this member.
Returns:
The thread in question
"""
return await self._client.cache.fetch_channel(self.id)
def get_thread(self) -> "TYPE_THREAD_CHANNEL":
"""
Gets the thread associated with with this member.
Returns:
The thread in question
"""
return self._client.cache.get_channel(self.id)
async def fetch_user(self) -> "User":
"""
Fetch the user associated with this thread member.
Returns:
The user object
"""
return await self._client.cache.fetch_user(self._user_id)
def get_user(self) -> "User":
"""
Get the user associated with this thread member.
Returns:
The user object
"""
return self._client.cache.get_user(self._user_id)
async def _send_http_request(
self, message_payload: Union[dict, "FormData"], files: list["UPLOADABLE_TYPE"] | None = None
) -> dict:
dm_id = await self._client.cache.fetch_dm_channel_id(self._user_id)
return await self._client.http.create_message(message_payload, dm_id, files=files)
async
inherited
method
send(self, content, embeds, embed, components, stickers, allowed_mentions, reply_to, files, file, tts, suppress_embeds, flags, delete_after, **kwargs)
¶
Send a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
Optional[str] |
Message text content. |
None |
embeds |
Union[List[Union[Embed, dict]], Embed, dict] |
Embedded rich content (up to 6000 characters). |
None |
embed |
Union[Embed, dict] |
Embedded rich content (up to 6000 characters). |
None |
components |
Union[List[List[Union[BaseComponent, dict]]], List[Union[BaseComponent, dict]], BaseComponent, dict] |
The components to include with the message. |
None |
stickers |
Union[List[Union[Sticker, Snowflake_Type]], Sticker, Snowflake_Type] |
IDs of up to 3 stickers in the server to send in the message. |
None |
allowed_mentions |
Union[AllowedMentions, dict] |
Allowed mentions for the message. |
None |
reply_to |
Union[MessageReference, Message, dict, Snowflake_Type] |
Message to reference, must be from the same channel. |
None |
files |
Union[UPLOADABLE_TYPE, List[UPLOADABLE_TYPE]] |
Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files. |
None |
file |
Optional[UPLOADABLE_TYPE] |
Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files. |
None |
tts |
bool |
Should this message use Text To Speech. |
False |
suppress_embeds |
bool |
Should embeds be suppressed on this send |
False |
flags |
Union[int, MessageFlags] |
Message flags to apply. |
None |
delete_after |
Optional[float] |
Delete message after this many seconds. |
None |
Returns:
Type | Description |
---|---|
Message |
New message object that was sent. |
Source code in naff/models/discord/thread.py
async def send(
self,
content: Optional[str] = None,
embeds: Optional[Union[List[Union["Embed", dict]], Union["Embed", dict]]] = None,
embed: Optional[Union["Embed", dict]] = None,
components: Optional[
Union[List[List[Union["BaseComponent", dict]]], List[Union["BaseComponent", dict]], "BaseComponent", dict]
] = None,
stickers: Optional[Union[List[Union["Sticker", "Snowflake_Type"]], "Sticker", "Snowflake_Type"]] = None,
allowed_mentions: Optional[Union["AllowedMentions", dict]] = None,
reply_to: Optional[Union["MessageReference", "Message", dict, "Snowflake_Type"]] = None,
files: Optional[Union["UPLOADABLE_TYPE", List["UPLOADABLE_TYPE"]]] = None,
file: Optional["UPLOADABLE_TYPE"] = None,
tts: bool = False,
suppress_embeds: bool = False,
flags: Optional[Union[int, "MessageFlags"]] = None,
delete_after: Optional[float] = None,
**kwargs,
) -> "Message":
"""
Send a message.
Args:
content: Message text content.
embeds: Embedded rich content (up to 6000 characters).
embed: Embedded rich content (up to 6000 characters).
components: The components to include with the message.
stickers: IDs of up to 3 stickers in the server to send in the message.
allowed_mentions: Allowed mentions for the message.
reply_to: Message to reference, must be from the same channel.
files: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
file: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
tts: Should this message use Text To Speech.
suppress_embeds: Should embeds be suppressed on this send
flags: Message flags to apply.
delete_after: Delete message after this many seconds.
Returns:
New message object that was sent.
"""
if not content and not (embeds or embed) and not (files or file) and not stickers:
raise errors.EmptyMessageException(
"You cannot send a message without any content, embeds, files, or stickers"
)
if suppress_embeds:
if isinstance(flags, int):
flags = MessageFlags(flags)
flags = flags | MessageFlags.SUPPRESS_EMBEDS
message_payload = models.discord.message.process_message_payload(
content=content,
embeds=embeds or embed,
components=components,
stickers=stickers,
allowed_mentions=allowed_mentions,
reply_to=reply_to,
tts=tts,
flags=flags,
**kwargs,
)
message_data = await self._send_http_request(message_payload, files=files or file)
if message_data:
message = self._client.cache.place_message_data(message_data)
if delete_after:
await message.delete(delay=delete_after)
return message
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/thread.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
async
method
fetch_thread(self)
¶
Fetches the thread associated with with this member.
Returns:
Type | Description |
---|---|
TYPE_THREAD_CHANNEL |
The thread in question |
Source code in naff/models/discord/thread.py
async def fetch_thread(self) -> "TYPE_THREAD_CHANNEL":
"""
Fetches the thread associated with with this member.
Returns:
The thread in question
"""
return await self._client.cache.fetch_channel(self.id)
method
get_thread(self)
¶
Gets the thread associated with with this member.
Returns:
Type | Description |
---|---|
TYPE_THREAD_CHANNEL |
The thread in question |
Source code in naff/models/discord/thread.py
def get_thread(self) -> "TYPE_THREAD_CHANNEL":
"""
Gets the thread associated with with this member.
Returns:
The thread in question
"""
return self._client.cache.get_channel(self.id)
async
method
fetch_user(self)
¶
Fetch the user associated with this thread member.
Returns:
Type | Description |
---|---|
User |
The user object |
Source code in naff/models/discord/thread.py
async def fetch_user(self) -> "User":
"""
Fetch the user associated with this thread member.
Returns:
The user object
"""
return await self._client.cache.fetch_user(self._user_id)
method
get_user(self)
¶
Get the user associated with this thread member.
Returns:
Type | Description |
---|---|
User |
The user object |
Source code in naff/models/discord/thread.py
def get_user(self) -> "User":
"""
Get the user associated with this thread member.
Returns:
The user object
"""
return self._client.cache.get_user(self._user_id)
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/thread.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
ThreadList (ClientObject)
¶
Represents a list of one or more threads.
Attr attributes:
Name | Type | Description |
---|---|---|
threads |
List[TYPE_THREAD_CHANNEL] |
The active threads. |
members |
List[naff.models.discord.thread.ThreadMember] |
A thread member object for each returned thread the current user has joined. |
has_more |
bool |
Whether there are potentially additional threads that could be returned on a subsequent call. |
Source code in naff/models/discord/thread.py
@define()
class ThreadList(ClientObject):
"""Represents a list of one or more threads."""
threads: List["TYPE_THREAD_CHANNEL"] = field(factory=list) # TODO Reference the cache or store actual object?
"""The active threads."""
members: List[ThreadMember] = field(factory=list)
"""A thread member object for each returned thread the current user has joined."""
has_more: bool = field(default=False)
"""Whether there are potentially additional threads that could be returned on a subsequent call."""
@classmethod
def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
threads = []
for thread_data in data["threads"]:
threads.append(client.cache.place_channel_data(thread_data))
data["threads"] = threads
data["members"] = ThreadMember.from_list(data["members"], client)
return data
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/thread.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/thread.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
ThreadTag (DiscordObject)
¶
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
Source code in naff/models/discord/thread.py
@define()
class ThreadTag(DiscordObject):
name: str = field()
emoji_id: "Snowflake_Type" = field(default=None)
emoji_name: str | None = field(default=None)
_parent_channel_id: "Snowflake_Type" = field(default=MISSING)
@property
def parent_channel(self) -> "GuildForum":
"""The parent forum for this tag."""
return self._client.get_channel(self._parent_channel_id)
async def edit(
self, *, name: Optional[str] = None, emoji: Union["models.PartialEmoji", dict, str, None] = None
) -> "ThreadTag":
"""
Edit this tag
Args:
name: The name for this tag
emoji: The emoji for this tag
Returns:
This object
"""
if isinstance(emoji, str):
emoji = PartialEmoji.from_str(emoji)
elif isinstance(emoji, dict):
emoji = PartialEmoji.from_dict(emoji)
if emoji.id:
data = await self._client.http.edit_tag(self._parent_channel_id, self.id, name, emoji_id=emoji.id)
else:
data = await self._client.http.edit_tag(self._parent_channel_id, self.id, name, emoji_name=emoji.name)
self._client.cache.place_channel_data(data)
for tag in data["available_tags"]:
if tag.id == self.id:
self.name = tag.name
self.emoji_id = tag.emoji_id
self.emoji_name = tag.emoji_name
break
return self
async def delete(self) -> None:
"""Delete this tag."""
data = await self._client.http.delete_tag(self._parent_channel_id, self.id)
self._client.cache.place_channel_data(data)
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/thread.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/thread.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
property
readonly
parent_channel: GuildForum
¶
The parent forum for this tag.
async
method
edit(self, *, name, emoji)
¶
Edit this tag
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str] |
The name for this tag |
None |
emoji |
Union[models.PartialEmoji, dict, str] |
The emoji for this tag |
None |
Returns:
Type | Description |
---|---|
ThreadTag |
This object |
Source code in naff/models/discord/thread.py
async def edit(
self, *, name: Optional[str] = None, emoji: Union["models.PartialEmoji", dict, str, None] = None
) -> "ThreadTag":
"""
Edit this tag
Args:
name: The name for this tag
emoji: The emoji for this tag
Returns:
This object
"""
if isinstance(emoji, str):
emoji = PartialEmoji.from_str(emoji)
elif isinstance(emoji, dict):
emoji = PartialEmoji.from_dict(emoji)
if emoji.id:
data = await self._client.http.edit_tag(self._parent_channel_id, self.id, name, emoji_id=emoji.id)
else:
data = await self._client.http.edit_tag(self._parent_channel_id, self.id, name, emoji_name=emoji.name)
self._client.cache.place_channel_data(data)
for tag in data["available_tags"]:
if tag.id == self.id:
self.name = tag.name
self.emoji_id = tag.emoji_id
self.emoji_name = tag.emoji_name
break
return self
async
method
delete(self)
¶
Delete this tag.
Source code in naff/models/discord/thread.py
async def delete(self) -> None:
"""Delete this tag."""
data = await self._client.http.delete_tag(self._parent_channel_id, self.id)
self._client.cache.place_channel_data(data)