DiscordPHP Documentation

ChannelTrait

Represents a guild or DM channel within Discord.

Tags
since
10.19.0
@property

?string|null $name The name of the channel or thread.

@property

?string|null $last_message_id The unique identifier of the last message sent in the channel or thread. (may not point to an existing or valid message or thread).

Table of Contents

Properties

$guild  : Guild|null
$guild_id  : string|null
$id  : string
$is_private  : bool
$last_pin_timestamp  : Carbon|null
$members  : MemberRepository
$messages  : MessageRepository
$owner  : User|null
$owner_id  : string|null
$owner_member  : Member|null
$parent  : Channel|null
$parent_id  : string
$rate_limit_per_user  : int|null
$type  : int

Methods

allowInvite()  : bool
Returns if allow invite.
allowText()  : bool
Returns if allow text.
allowVoice()  : bool
Returns if allow voice.
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.
getBotPermissions()  : RolePermission|null
Returns the bot's permissions in the thread.
getMessageHistory()  : PromiseInterface<string|int, Collection<string|int, array<string|int, Message>>>
Fetches message history.
getPinnedMessages()  : PromiseInterface<string|int, MessagePinData|null>
Returns the channels pinned messages.
isTextBased()  : bool
Returns if channel type is text based.
isVoiceBased()  : bool
Returns if channel type is voice based.
pinMessage()  : PromiseInterface<string|int, Message>
Pin a message in a channel.
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.
unpinMessage()  : PromiseInterface
Removes a message from the channels pinboard.
getGuildAttribute()  : Guild|null
Returns the guild which the thread belongs to.
getIsPrivateAttribute()  : bool
Gets the is_private attribute.
getLastPinTimestampAttribute()  : Carbon|null
Gets the last pinned message timestamp.
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.

Properties

$guild read-only

public Guild|null $guild

The guild that the channel or thread belongs to. Only for text or voice channels.

$guild_id

public string|null $guild_id

The ID of the guild that the channel or thread belongs to. Only for text or voice channels.

$is_private

public bool $is_private

Whether the channel is a private channel.

$last_pin_timestamp

public Carbon|null $last_pin_timestamp

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

$members

public MemberRepository $members

Voice channel only - members in the channel or thread.

$messages

public MessageRepository $messages

Text channel only - messages sent in the channel or thread.

$owner read-only

public User|null $owner

The DM creator or the owner of the thread.

$owner_id

public string|null $owner_id

The ID of the DM creator (Only for DM or group channels) or the owner of the thread.

$owner_member read-only

public Member|null $owner_member

The member object for the DM creator or the owner of the thread.

$parent read-only

public Channel|null $parent

The parent channel or the channel which the thread was created in.

$parent_id

public string $parent_id

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

$rate_limit_per_user

public int|null $rate_limit_per_user

Amount of seconds a user has to wait before sending a new message (slow mode).

Methods

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.

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

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<string|int, MessagePinData|null>
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
since
10.19.0

Added $options parameter to allow for pagination. Returns MessagePinData or null instead of Collection. Use MessagePinData?->items instead.

Return values
PromiseInterface<string|int, MessagePinData|null>

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.

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 pin_messages or manage_messages permission.

throws
RuntimeException
todo

Remove manage_messages permission check on January 12, 2026.

since
10.19.0

Updated endpoint to use the new pin message endpoint.

Return values
PromiseInterface<string|int, Message>

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>

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 pin_messages or manage_messages permission.

throws
RuntimeException
todo

Remove manage_messages permission check on January 12, 2026.

since
10.19.0

Updated endpoint to use the new unpin message endpoint.

Return values
PromiseInterface

getGuildAttribute()

Returns the guild which the thread belongs to.

protected getGuildAttribute() : Guild|null
Return values
Guild|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

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

        
On this page

Search results