DiscordPHP Documentation

Thread extends Part
in package

Represents a Discord thread.

Tags
link
https://discord.com/developers/docs/topics/threads
since
7.0.0

Table of Contents

FLAG_PINNED  = 1 << 1
$applied_tags  : array<string|int, string>|null
$archive_timestamp  : Carbon
$archived  : bool
$auto_archive_duration  : int|null
$create_timestamp  : Carbon|null
$created  : bool
Is the part already created in the Discord servers?
$flags  : int|null
$guild  : Guild|null
$guild_id  : string
$id  : string
$invitable  : bool|null
$last_message_id  : string
$last_pin_timestamp  : Carbon|null
$locked  : bool
$member_count  : int
$members  : MemberRepository
$message_count  : int
$messages  : MessageRepository
$name  : string
$owner  : User|null
$owner_id  : string
$owner_member  : Member|null
$parent  : Channel|null
$parent_id  : string
$rate_limit_per_user  : int
$scriptData  : mixed
Custom script data.
$thread_metadata  : object
$total_message_sent  : int|null
$type  : string
$attributes  : array<string|int, mixed>
The parts attributes.
$discord  : Discord
The Discord client.
$factory  : Factory
The factory.
$fillable  : array<string|int, mixed>
The parts fillable attributes.
$hidden  : array<string|int, mixed>
Attributes that are hidden from debug info.
$http  : Http
The HTTP client.
$repositories  : array<string|int, mixed>
An array of repositories that can exist in a part.
$repositories_cache  : array<string|int, mixed>
An array of repositories.
$visible  : array<string|int, mixed>
Attributes which are visible from debug info.
__construct()  : mixed
Create a new part instance.
__debugInfo()  : array<string|int, mixed>
Handles debug calls from var_dump and similar functions.
__get()  : mixed
Handles dynamic get calls onto the part.
__serialize()  : array<string|int, mixed>
__set()  : void
Handles dynamic set calls onto the part.
__toString()  : string
Returns a formatted mention.
__unserialize()  : void
addMember()  : ExtendedPromiseInterface
Attempts to add a user to the thread.
archive()  : ExtendedPromiseInterface<string|int, Thread>
Archive the thread.
createMessageCollector()  : ExtendedPromiseInterface<string|int, Collection<string|int, Message>>
Creates a message collector for the channel.
deleteMessages()  : ExtendedPromiseInterface
Bulk deletes an array of messages.
ExtendedPromiseInterface()  : void
fetch()  : ExtendedPromiseInterface<string|int, self>
Fetches any missing information about the part from Discord's servers.
fill()  : void
Fills the parts attributes from an array.
getBotPermissions()  : RolePermission|null
Returns the bot's permissions in the thread.
getCreatableAttributes()  : array<string|int, mixed>
Returns the attributes needed to create.
getMessageHistory()  : ExtendedPromiseInterface<string|int, Collection<string|int, Message>>
Fetches the message history of the thread with a given array of arguments.
getPinnedMessages()  : ExtendedPromiseInterface<string|int, Collection<string|int, Message>>
Returns the thread's pinned messages.
getPublicAttributes()  : array<string|int, mixed>
Returns an array of public attributes.
getRawAttributes()  : array<string|int, mixed>
Returns an array of raw attributes.
getRepositoryAttributes()  : array<string|int, mixed>
Gets the attributes to pass to repositories.
getUpdatableAttributes()  : array<string|int, mixed>
Returns the updatable attributes.
isPartial()  : bool
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
join()  : ExtendedPromiseInterface
Attempts to join the thread.
jsonSerialize()  : array<string|int, mixed>
Provides data when the part is encoded into JSON. Used for JsonSerializable.
leave()  : ExtendedPromiseInterface
Attempts to leave the thread.
offsetExists()  : bool
Checks if an attribute exists via key. Used for ArrayAccess.
offsetGet()  : mixed
Gets an attribute via key. Used for ArrayAccess.
offsetSet()  : void
Sets an attribute via key. Used for ArrayAccess.
offsetUnset()  : void
Unsets an attribute via key. Used for ArrayAccess.
pinMessage()  : ExtendedPromiseInterface<string|int, Message>
Pins a message in the thread.
removeMember()  : ExtendedPromiseInterface
Attempts to remove a user from the thread.
rename()  : ExtendedPromiseInterface<string|int, Thread>
Rename the thread.
sendEmbed()  : ExtendedPromiseInterface<string|int, Message>
Sends an embed to the thread.
sendMessage()  : ExtendedPromiseInterface<string|int, Message>
Sends a message to the thread.
serialize()  : string|null
Serializes the data. Used for Serializable.
setAutoArchiveDuration()  : ExtendedPromiseInterface<string|int, Thread>
Set auto archive duration of the thread.
unarchive()  : ExtendedPromiseInterface<string|int, Thread>
Unarchive the thread.
unpinMessage()  : ExtendedPromiseInterface<string|int, Message>
Unpins a message in the thread.
unserialize()  : void
Unserializes some data and stores it. Used for Serializable.
afterConstruct()  : void
Called after the part has been constructed.
getArchivedAttribute()  : bool
Returns whether the thread is archived.
getArchiveTimestampAttribute()  : Carbon
Returns the time that the thread's archive status was changed.
getAutoArchiveDurationAttribute()  : int|null
Returns the number of minutes of inactivity required for the thread to auto archive.
getCreateTimestampAttribute()  : Carbon|null
Returns the timestamp when the thread was created; only populated for threads created after 2022-01-09.
getGuildAttribute()  : Guild|null
Returns the guild which the thread belongs to.
getInvitableAttribute()  : bool|null
Returns whether the thread is archived.
getLastPinTimestampAttribute()  : Carbon|null
Returns the timestamp when the last message was pinned in the thread.
getLockedAttribute()  : bool
Returns whether the thread has been locked.
getOwnerAttribute()  : User|null
Returns the owner of the thread.
getOwnerMemberAttribute()  : Member|null
Returns the member object for the owner of the thread.
getParentAttribute()  : Channel|null
Returns the parent channel of the thread.
setArchivedAttribute()  : mixed
Set whether the thread is archived.
setAutoArchiveDurationAttribute()  : mixed
Set the number of minutes of inactivity required for the thread to auto archive.
setLockedAttribute()  : mixed
Set whether the thread is locked.
checkForMutator()  : string|false
Checks if there is a mutator present.
getAttribute()  : mixed
Gets an attribute on the part.
setAttribute()  : void
Sets an attribute on the part.
studly()  : string
Converts a string to studlyCase.

Constants

FLAG_PINNED

public mixed FLAG_PINNED = 1 << 1

Properties

$applied_tags

public array<string|int, string>|null $applied_tags

The IDs of the set of tags that have been applied to a thread in a forum channel, limited to 5.

$archive_timestamp

public Carbon $archive_timestamp

The time that the thread's archive status was changed.

$archived

public bool $archived

Whether the thread has been archived.

$auto_archive_duration

public int|null $auto_archive_duration

The number of minutes of inactivity until the thread is automatically archived.

$create_timestamp

public Carbon|null $create_timestamp

Timestamp when the thread was created; only populated for threads created after 2022-01-09.

$created

Is the part already created in the Discord servers?

public bool $created = false

Whether the part has been created.

$flags

public int|null $flags

Channel flags combined as a bitfield. PINNED can only be set for threads in forum channels.

$guild read-only

public Guild|null $guild

The guild which the thread belongs to.

$guild_id

public string $guild_id

The ID of the guild which the thread belongs to.

$id

public string $id

The ID of the thread.

$invitable

public bool|null $invitable

Whether non-moderators can add other non-moderators to a thread; only available on private threads.

$last_message_id

public string $last_message_id

The ID of the last message sent in the thread.

$last_pin_timestamp

public Carbon|null $last_pin_timestamp

The timestamp when the last message was pinned in the thread.

$locked

public bool $locked

Whether the thread has been locked.

$member_count

public int $member_count

An approximate count of the number of members in the thread. Stops counting at 50.

$message_count

public int $message_count

Number of messages (not including the initial message or deleted messages) in a thread (if the thread was created before July 1, 2022, the message count is inaccurate when it's greater than 50).

$name

public string $name

The name of the thread.

$owner read-only

public User|null $owner

The owner of the thread.

$owner_id

public string $owner_id

The ID of the owner of the thread.

$owner_member read-only

public Member|null $owner_member

The member object for the owner of the thread.

$parent read-only

public Channel|null $parent

The channel which the thread was created in.

$parent_id

public string $parent_id

The ID of the channel which the thread was started in.

$rate_limit_per_user

public int $rate_limit_per_user

Amount of seconds a user has to wait before sending a new message.

$scriptData

Custom script data.

public mixed $scriptData

Used for storing custom information, used by end products.

Tags
deprecated
10.0.0

Relying on this variable with dynamic caching is discouraged.

$thread_metadata

public object $thread_metadata

Thread-specific fields not needed by other channels.

$total_message_sent

public int|null $total_message_sent

Number of messages ever sent in a thread, it's similar to message_count on message creation, but will not decrement the number when a message is deleted.

$type

public string $type

The type of thread.

$attributes

The parts attributes.

protected array<string|int, mixed> $attributes = []

The parts attributes and content.

$discord

The Discord client.

protected Discord $discord

Client.

$fillable

The parts fillable attributes.

protected array<string|int, mixed> $fillable = ['id', 'type', 'guild_id', 'name', 'last_message_id', 'last_pin_timestamp', 'rate_limit_per_user', 'owner_id', 'parent_id', 'message_count', 'member_count', 'thread_metadata', 'member', 'total_message_sent', 'flags', 'applied_tags']

The array of attributes that can be mass-assigned.

$hidden

Attributes that are hidden from debug info.

protected array<string|int, mixed> $hidden = ['member']

Attributes that are hidden from public.

$http

The HTTP client.

protected Http $http

Client.

$repositories

An array of repositories that can exist in a part.

protected array<string|int, mixed> $repositories = ['messages' => \Discord\Repository\Channel\MessageRepository::class, 'members' => \Discord\Repository\Thread\MemberRepository::class]

Repositories.

$repositories_cache

An array of repositories.

protected array<string|int, mixed> $repositories_cache = []

$visible

Attributes which are visible from debug info.

protected array<string|int, mixed> $visible = []

Methods

__construct()

Create a new part instance.

public __construct(Discord $discord[, array<string|int, mixed> $attributes = [] ][, bool $created = false ]) : mixed
Parameters
$discord : Discord

The Discord client.

$attributes : array<string|int, mixed> = []

An array of attributes to build the part.

$created : bool = false

Whether the part has already been created.

Return values
mixed

__debugInfo()

Handles debug calls from var_dump and similar functions.

public __debugInfo() : array<string|int, mixed>
Tags
throws
Exception
see
Part::getPublicAttributes()

This function forwards onto getPublicAttributes.

Return values
array<string|int, mixed>

An array of public attributes.

__get()

Handles dynamic get calls onto the part.

public __get(string $key) : mixed
Parameters
$key : string

The attributes key.

Tags
throws
Exception
see
Part::getAttribute()

This function forwards onto getAttribute.

Return values
mixed

The value of the attribute.

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__set()

Handles dynamic set calls onto the part.

public __set(string $key, mixed $value) : void
Parameters
$key : string

The attributes key.

$value : mixed

The attributes value.

Tags
see
self::setAttribute()

This function forwards onto setAttribute.

Return values
void

__toString()

Returns a formatted mention.

public __toString() : string
Return values
string

A formatted mention.

__unserialize()

public __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Return values
void

archive()

Archive the thread.

public archive([string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Thread>
Parameters
$reason : string|null = null

Reason for Audit Log.

Return values
ExtendedPromiseInterface<string|int, Thread>

createMessageCollector()

Creates a message collector for the channel.

public createMessageCollector(callable $filter[, int $options = [] ]) : ExtendedPromiseInterface<string|int, Collection<string|int, Message>>
Parameters
$filter : callable

The filter function. Returns true or false.

$options : int = []

['limit'] The amount of messages allowed or false.

Tags
todo

Make it in a trait along with Channel

Return values
ExtendedPromiseInterface<string|int, Collection<string|int, Message>>

deleteMessages()

Bulk deletes an array of messages.

public deleteMessages(array<string|int, mixed> $messages[, string|null $reason = null ]) : ExtendedPromiseInterface
Parameters
$messages : array<string|int, mixed>
$reason : string|null = null

Reason for Audit Log (only for bulk messages).

Tags
link
https://discord.com/developers/docs/resources/channel#bulk-delete-messages
todo

Make it in a trait along with Channel

Return values
ExtendedPromiseInterface

ExtendedPromiseInterface()

public ExtendedPromiseInterface() : void

<Message> sendMessage(MessageBuilder $builder)

Return values
void

fetch()

Fetches any missing information about the part from Discord's servers.

public fetch() : ExtendedPromiseInterface<string|int, self>
Tags
throws
RuntimeException

The part is not fetchable.

Return values
ExtendedPromiseInterface<string|int, self>

fill()

Fills the parts attributes from an array.

public fill(array<string|int, mixed> $attributes) : void
Parameters
$attributes : array<string|int, mixed>

An array of attributes to build the part.

Return values
void

getMessageHistory()

Fetches the message history of the thread with a given array of arguments.

public getMessageHistory(array<string|int, mixed> $options) : ExtendedPromiseInterface<string|int, Collection<string|int, Message>>
Parameters
$options : array<string|int, mixed>
Tags
link
https://discord.com/developers/docs/resources/channel#get-channel-messages
todo

Make it in a trait along with Channel

Return values
ExtendedPromiseInterface<string|int, Collection<string|int, Message>>

getPublicAttributes()

Returns an array of public attributes.

public getPublicAttributes() : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, mixed>

An array of public attributes.

getRawAttributes()

Returns an array of raw attributes.

public getRawAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Raw attributes.

getRepositoryAttributes()

Gets the attributes to pass to repositories.

public getRepositoryAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Attributes.

isPartial()

Whether the part is considered partial i.e. missing information which can be fetched from Discord.

public isPartial() : bool
Return values
bool

jsonSerialize()

Provides data when the part is encoded into JSON. Used for JsonSerializable.

public jsonSerialize() : array<string|int, mixed>
Tags
throws
Exception
see
Part::getPublicAttributes()

This function forwards onto getPublicAttributes.

Return values
array<string|int, mixed>

An array of public attributes.

offsetExists()

Checks if an attribute exists via key. Used for ArrayAccess.

public offsetExists(string $key) : bool
Parameters
$key : string

The attribute key.

Return values
bool

Whether the offset exists.

offsetGet()

Gets an attribute via key. Used for ArrayAccess.

public offsetGet(string $key) : mixed
Parameters
$key : string

The attribute key.

Tags
throws
Exception
see
Part::getAttribute()

This function forwards onto getAttribute.

Return values
mixed

offsetSet()

Sets an attribute via key. Used for ArrayAccess.

public offsetSet(string $key, mixed $value) : void
Parameters
$key : string

The attribute key.

$value : mixed

The attribute value.

Tags
see
Part::setAttribute()

This function forwards onto setAttribute.

Return values
void

offsetUnset()

Unsets an attribute via key. Used for ArrayAccess.

public offsetUnset(string $key) : void
Parameters
$key : string

The attribute key.

Return values
void

rename()

Rename the thread.

public rename(string $name[, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Thread>
Parameters
$name : string

New thread name.

$reason : string|null = null

Reason for Audit Log.

Return values
ExtendedPromiseInterface<string|int, Thread>

sendEmbed()

Sends an embed to the thread.

public sendEmbed(Embed $embed) : ExtendedPromiseInterface<string|int, Message>
Parameters
$embed : Embed

Embed to send.

Tags
deprecated
10.0.0

Use Channel::sendMessage with MessageBuilder::addEmbed()

see
Thread::sendMessage()
todo

Make it in a trait along with Channel

Return values
ExtendedPromiseInterface<string|int, Message>

sendMessage()

Sends a message to the thread.

public sendMessage(MessageBuilder|string $message[, bool $tts = false ][, Embed|array<string|int, mixed>|null $embed = null ][, array<string|int, mixed>|null $allowed_mentions = null ][, Message|null $replyTo = null ]) : ExtendedPromiseInterface<string|int, Message>

Takes a MessageBuilder or content of the message for the first parameter. If the first parameter is an instance of MessageBuilder, the rest of the arguments are disregarded.

Parameters
$message : MessageBuilder|string

The message builder that should be converted into a message, or the string content of the message.

$tts : bool = false

Whether the message is TTS.

$embed : Embed|array<string|int, mixed>|null = null

An embed object or array to send in the message.

$allowed_mentions : array<string|int, mixed>|null = null

Allowed mentions object for the message.

$replyTo : Message|null = null

Sends the message as a reply to the given message instance.

Tags
link
https://discord.com/developers/docs/resources/channel#create-message
todo

Make it in a trait along with Channel

Return values
ExtendedPromiseInterface<string|int, Message>

serialize()

Serializes the data. Used for Serializable.

public serialize() : string|null
Return values
string|null

A string of serialized data.

setAutoArchiveDuration()

Set auto archive duration of the thread.

public setAutoArchiveDuration(int $duration[, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Thread>
Parameters
$duration : int

Duration in minutes.

$reason : string|null = null

Reason for Audit Log.

Return values
ExtendedPromiseInterface<string|int, Thread>

unarchive()

Unarchive the thread.

public unarchive([string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Thread>
Parameters
$reason : string|null = null

Reason for Audit Log.

Return values
ExtendedPromiseInterface<string|int, Thread>

unserialize()

Unserializes some data and stores it. Used for Serializable.

public unserialize(string $data) : void
Parameters
$data : string

Some serialized data.

Tags
see
Part::setAttribute()

The unserialized data is stored with setAttribute.

Return values
void

afterConstruct()

Called after the part has been constructed.

protected afterConstruct() : void
Return values
void

getArchivedAttribute()

Returns whether the thread is archived.

protected getArchivedAttribute() : bool
Return values
bool

getArchiveTimestampAttribute()

Returns the time that the thread's archive status was changed.

protected getArchiveTimestampAttribute() : Carbon

Note that this does not mean the time that the thread was archived - it can also mean the time when the thread was created, archived, unarchived etc.

Tags
throws
Exception
Return values
Carbon

getAutoArchiveDurationAttribute()

Returns the number of minutes of inactivity required for the thread to auto archive.

protected getAutoArchiveDurationAttribute() : int|null
Return values
int|null

getCreateTimestampAttribute()

Returns the timestamp when the thread was created; only populated for threads created after 2022-01-09.

protected getCreateTimestampAttribute() : Carbon|null
Tags
throws
Exception
Return values
Carbon|null

getGuildAttribute()

Returns the guild which the thread belongs to.

protected getGuildAttribute() : Guild|null
Return values
Guild|null

getInvitableAttribute()

Returns whether the thread is archived.

protected getInvitableAttribute() : bool|null
Return values
bool|null

getLastPinTimestampAttribute()

Returns the timestamp when the last message was pinned in the thread.

protected getLastPinTimestampAttribute() : Carbon|null
Tags
throws
Exception
Return values
Carbon|null

getLockedAttribute()

Returns whether the thread has been locked.

protected getLockedAttribute() : bool
Return values
bool

getOwnerAttribute()

Returns the owner of the thread.

protected getOwnerAttribute() : User|null
Return values
User|null

getOwnerMemberAttribute()

Returns the member object for the owner of the thread.

protected getOwnerMemberAttribute() : Member|null
Return values
Member|null

getParentAttribute()

Returns the parent channel of the thread.

protected getParentAttribute() : Channel|null
Return values
Channel|null

setArchivedAttribute()

Set whether the thread is archived.

protected setArchivedAttribute(bool $value) : mixed
Parameters
$value : bool
Return values
mixed

setAutoArchiveDurationAttribute()

Set the number of minutes of inactivity required for the thread to auto archive.

protected setAutoArchiveDurationAttribute(int $value) : mixed
Parameters
$value : int
Return values
mixed

setLockedAttribute()

Set whether the thread is locked.

protected setLockedAttribute(bool $value) : mixed
Parameters
$value : bool
Return values
mixed

checkForMutator()

Checks if there is a mutator present.

private checkForMutator(string $key, string $type) : string|false
Parameters
$key : string

The attribute name to check.

$type : string

Either get or set.

Return values
string|false

Either a string if it is callable or false.

getAttribute()

Gets an attribute on the part.

private getAttribute(string $key) : mixed
Parameters
$key : string

The key to the attribute.

Tags
throws
Exception
Return values
mixed

Either the attribute if it exists or void.

setAttribute()

Sets an attribute on the part.

private setAttribute(string $key, mixed $value) : void
Parameters
$key : string

The key to the attribute.

$value : mixed

The value of the attribute.

Return values
void

studly()

Converts a string to studlyCase.

private static studly(string $string) : string

This is a port of updated Laravel's implementation, a non-regex with static cache. The Discord\studly() is kept due to unintended bug and we do not want to introduce BC by replacing it. This method is private static as we may move it outside this class in future.

Parameters
$string : string

The string to convert.

Tags
since
10.0.0
Return values
string

Search results