DiscordPHP Documentation

Thread extends Part
in package
implements Stringable uses ChannelTrait

Represents a Discord thread.

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

Table of Contents

Interfaces

Stringable

Constants

FLAG_PINNED  = 1 << 1

Properties

$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
$invitable  : bool|null
$locked  : bool
$member_count  : int
$message_count  : int
$scriptData  : mixed
Custom script data.
$thread_metadata  : object
$total_message_sent  : int|null
$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.

Methods

__construct()  : mixed
Create a new part instance.
__debugInfo()  : array<string|int, mixed>
__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()  : PromiseInterface
Attempts to add a user to the thread.
allowInvite()  : bool
Returns if allow invite.
allowText()  : bool
Returns if allow text.
allowVoice()  : bool
Returns if allow voice.
archive()  : PromiseInterface<string|int, self>
Archive the thread.
broadcastTyping()  : PromiseInterface
Broadcasts that you are typing to the channel. Lasts for 5 seconds.
canInvite()  : bool
Returns if invite can be created in this type of channel.
createMessageCollector()  : PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>
Creates a message collector for the channel.
deleteMessages()  : PromiseInterface
Bulk deletes an array of messages.
fetch()  : PromiseInterface<string|int, static>
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>
getDiscord()  : Discord
Get the Discord instance that owns this Part.
getMessageHistory()  : PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>
Fetches message history.
getPinnedMessages()  : PromiseInterface
Returns the channels 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>
getUpdatableAttributes()  : array<string|int, mixed>
isPartial()  : bool
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
isTextBased()  : bool
Returns if channel type is text based.
isVoiceBased()  : bool
Returns if channel type is voice based.
join()  : PromiseInterface
Attempts to join the thread.
jsonSerialize()  : array<string|int, mixed>
Provides data when the part is encoded into JSON. Used for JsonSerializable.
leave()  : PromiseInterface
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()  : PromiseInterface<string|int, Message>
Pin a message in a channel.
removeMember()  : PromiseInterface
Attempts to remove a user from the thread.
rename()  : PromiseInterface<string|int, self>
Rename the thread.
sendEmbed()  : PromiseInterface<string|int, Message>
Sends an embed to the channel.
sendFile()  : PromiseInterface<string|int, Message>
Sends a file to the channel.
sendMessage()  : PromiseInterface<string|int, Message>
Sends a message to the channel.
serialize()  : string|null
Serializes the data. Used for Serializable.
setAutoArchiveDuration()  : PromiseInterface<string|int, self>
Set auto archive duration of the thread.
unarchive()  : PromiseInterface<string|int, self>
Unarchive the thread.
unpinMessage()  : PromiseInterface
Removes a message from the channels pinboard.
unserialize()  : void
Unserializes some data and stores it. Used for Serializable.
afterConstruct()  : void
{@inheritDoc}
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.
getIsPrivateAttribute()  : bool
Gets the is_private attribute.
getLastPinTimestampAttribute()  : Carbon|null
Gets the last pinned message timestamp.
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.
makeOptionalAttributes()  : array<string|int, mixed>
Return key-value attributes if it has been filled.
setArchivedAttribute()  : void
Set whether the thread is archived.
setAutoArchiveDurationAttribute()  : void
Set the number of minutes of inactivity required for the thread to auto archive.
setInvitableAttribute()  : void
Sets whether members without `MANAGE_THREADS` can invite other members without `MANAGE_THREADS` Always `null` in public threads
setLockedAttribute()  : void
Set whether the thread is locked.
checkForGetMutator()  : string|false
Checks if there is a get mutator present.
checkForSetMutator()  : string|false
Checks if there is a set 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.

$invitable

public bool|null $invitable

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

$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).

$scriptData

Custom script data.

Relying on this variable with dynamic caching is discouraged.

public mixed $scriptData

Used for storing custom information, used by end products.

$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.

$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', // events 'newly_created', ]

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 = ['members' => \Discord\Repository\Thread\MemberRepository::class, 'messages' => \Discord\Repository\Channel\MessageRepository::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.

__debugInfo()

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

__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.

__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>

allowInvite()

Returns if allow invite.

public allowInvite() : bool

Use Channel::canInvite()

Return values
bool

if we can make invite or not.

allowText()

Returns if allow text.

public allowText() : bool

Use Channel::isTextBased()

Return values
bool

if we can send text or not.

allowVoice()

Returns if allow voice.

public allowVoice() : bool

Use Channel::isVoiceBased()

Return values
bool

if we can send voice or not.

archive()

Archive the thread.

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

Reason for Audit Log.

Return values
PromiseInterface<string|int, self>

canInvite()

Returns if invite can be created in this type of channel.

public canInvite() : bool
Return values
bool

Whether the channel type is possible for creating invite.

createMessageCollector()

Creates a message collector for the channel.

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

The filter function. Returns true or false.

$options : int = []

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

Return values
PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>

deleteMessages()

Bulk deletes an array of messages.

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

An array of messages to delete.

$reason : string|null = null

Reason for Audit Log (only for bulk messages).

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

Missing manage_messages permission.

Return values
PromiseInterface

fetch()

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

public fetch() : PromiseInterface<string|int, static>
Tags
throws
RuntimeException

The part is not fetchable.

Return values
PromiseInterface<string|int, static>

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.

Tags
see
self::setAttribute()

getMessageHistory()

Fetches message history.

public getMessageHistory([int|null $options = [] ]) : PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>
Parameters
$options : int|null = []

['limit'] Max number of messages to return (1-100). Defaults to 50.

Tags
link
https://discord.com/developers/docs/resources/channel#get-channel-messages
throws
NoPermissionsException

Missing read_message_history permission. Or also missing connect permission for text in voice.

throws
RangeException
Return values
PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>

getPinnedMessages()

Returns the channels pinned messages.

public getPinnedMessages([Message|Carbon|string $options = [] ]) : PromiseInterface
Parameters
$options : Message|Carbon|string = []

['before'] A message or timestamp to get messages before.

Tags
link
https://discord.com/developers/docs/resources/message#get-channel-pins
@return

PromiseInterface<Collection<MessagePinData>

since
10.19.0

Added $options parameter to allow for pagination.

Return values
PromiseInterface

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()

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

isPartial()

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

public isPartial() : bool
Return values
bool

isTextBased()

Returns if channel type is text based.

public isTextBased() : bool
Return values
bool

Whether the channel is possible for sending text.

isVoiceBased()

Returns if channel type is voice based.

public isVoiceBased() : bool
Return values
bool

Whether the channel is possible for voice.

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.

Attributes
#[ReturnTypeWillChange]

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.

offsetUnset()

Unsets an attribute via key. Used for ArrayAccess.

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

The attribute key.

pinMessage()

Pin a message in a channel.

public pinMessage(Message $message[, string|null $reason = null ]) : PromiseInterface<string|int, Message>
Parameters
$message : Message

The message to pin.

$reason : string|null = null

Reason for Audit Log.

Tags
link
https://discord.com/developers/docs/resources/message#pin-message
throws
NoPermissionsException

Missing manage_messages permission.

throws
RuntimeException
since
10.19.0

Updated endpoint to use the new pin message endpoint.

Return values
PromiseInterface<string|int, Message>

rename()

Rename the thread.

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

New thread name.

$reason : string|null = null

Reason for Audit Log.

Return values
PromiseInterface<string|int, self>

sendEmbed()

Sends an embed to the channel.

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

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

Parameters
$embed : Embed

Embed to send.

Tags
see
Channel::sendMessage()
Return values
PromiseInterface<string|int, Message>

sendFile()

Sends a file to the channel.

public sendFile(string $filepath[, string|null $filename = null ][, string|null $content = null ][, bool $tts = false ]) : PromiseInterface<string|int, Message>

Use Channel::sendMessage to send files.

Parameters
$filepath : string

The path to the file to be sent.

$filename : string|null = null

The name to send the file as.

$content : string|null = null

Message content to send with the file.

$tts : bool = false

Whether to send the message with TTS.

Tags
see
Channel::sendMessage()
Return values
PromiseInterface<string|int, Message>

sendMessage()

Sends a message to the channel.

public sendMessage(MessageBuilder|string $message[, bool $tts = false ][, Embed|array<string|int, mixed>|null $embed = null ][, AllowedMentions|array<string|int, mixed>|null $allowed_mentions = null ][, Message|null $replyTo = null ]) : PromiseInterface<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 : AllowedMentions|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
throws
RuntimeException
throws
NoPermissionsException

Missing various permissions depending on the message body.

Return values
PromiseInterface<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 ]) : PromiseInterface<string|int, self>
Parameters
$duration : int

Duration in minutes.

$reason : string|null = null

Reason for Audit Log.

Return values
PromiseInterface<string|int, self>

unarchive()

Unarchive the thread.

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

Reason for Audit Log.

Return values
PromiseInterface<string|int, self>

unpinMessage()

Removes a message from the channels pinboard.

public unpinMessage(Message $message[, string|null $reason = null ]) : PromiseInterface
Parameters
$message : Message

The message to un-pin.

$reason : string|null = null

Reason for Audit Log.

Tags
link
https://discord.com/developers/docs/resources/message#unpin-message
throws
NoPermissionsException

Missing manage_messages permission.

throws
RuntimeException
since
10.19.0

Updated endpoint to use the new unpin message endpoint.

Return values
PromiseInterface

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.

afterConstruct()

{@inheritDoc}

protected afterConstruct() : 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

getIsPrivateAttribute()

Gets the is_private attribute.

protected getIsPrivateAttribute() : bool
Return values
bool

Whether the channel is private.

getLastPinTimestampAttribute()

Gets the last pinned message timestamp.

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

makeOptionalAttributes()

Return key-value attributes if it has been filled.

protected makeOptionalAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>

To be used with fields marked "optional?" from the API.

Parameters
$attributes : array<string|int, mixed>

Names of optional attribute

Return values
array<string|int, mixed>

setArchivedAttribute()

Set whether the thread is archived.

protected setArchivedAttribute(bool $value) : void
Parameters
$value : bool

setAutoArchiveDurationAttribute()

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

protected setAutoArchiveDurationAttribute(int $value) : void
Parameters
$value : int

setInvitableAttribute()

Sets whether members without `MANAGE_THREADS` can invite other members without `MANAGE_THREADS` Always `null` in public threads

protected setInvitableAttribute(bool $value) : void
Parameters
$value : bool

setLockedAttribute()

Set whether the thread is locked.

protected setLockedAttribute(bool $value) : void
Parameters
$value : bool

checkForGetMutator()

Checks if there is a get mutator present.

private checkForGetMutator(string $key) : string|false
Parameters
$key : string

The attribute name to check.

Tags
since
10.0.0

Replaces checkForMutator($key, 'get')

Return values
string|false

Either a string if it is a method or false.

checkForSetMutator()

Checks if there is a set mutator present.

private checkForSetMutator(string $key) : string|false
Parameters
$key : string

The attribute name to check.

Tags
since
10.0.0

Replaces checkForMutator($key, 'set')

Return values
string|false

Either a string if it is a method 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.

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

        
On this page

Search results