DiscordPHP Documentation

Section extends Layout
in package
implements ComponentV2

Section components allow you to define up to 3 text display components and add either a thumbnail or button to the right side.

Tags
link
https://discord.com/developers/docs/interactions/message-components#section
since
10.5.0

Table of Contents

Interfaces

ComponentV2
This interface is a contract for V2 components.

Constants

TYPE_ACTION_ROW  = 1
TYPE_BUTTON  = 2
TYPE_CHANNEL_SELECT  = 8
TYPE_CONTAINER  = 17
TYPE_CONTENT_INVENTORY_ENTRY  = 16
TYPE_FILE  = 13
TYPE_MEDIA_GALLERY  = 12
TYPE_MENTIONABLE_SELECT  = 7
TYPE_ROLE_SELECT  = 6
TYPE_SECTION  = 9
TYPE_SELECT_MENU  = 3
TYPE_SEPARATOR  = 14
TYPE_STRING_SELECT  = 3
TYPE_TEXT_DISPLAY  = 10
TYPE_TEXT_INPUT  = 4
TYPE_THUMBNAIL  = 11
TYPE_USER_SELECT  = 5
USAGE  = ['Message']

Properties

$id  : int|null
32 bit integer used as an optional identifier for component.
$type  : int
Component type.
$accessory  : Thumbnail|Button|null
Accessory component (Thumbnail or Button).
$components  : array<string|int, TextDisplay>
Array of text display components.

Methods

addComponent()  : $this
Adds a text display component to the section.
getAccessory()  : Thumbnail|Button|null
Returns the accessory component.
getComponents()  : array<string|int, TextDisplay>
Returns all the text components in the section.
getCustomId()  : string|null
Returns the custom ID of the button.
getType()  : int
Retrieves the type of the component.
jsonSerialize()  : array<string|int, mixed>
{@inheritDoc}
new()  : self
Creates a new section.
setAccessory()  : $this
Sets the accessory component of the section.
generateUuid()  : string
Generates a UUID which can be used for component custom IDs.
getId()  : int|null
The id field is optional and is used to identify components in the response from an interaction that aren't interactive components.

Constants

TYPE_ACTION_ROW

public mixed TYPE_ACTION_ROW = 1

TYPE_CHANNEL_SELECT

public mixed TYPE_CHANNEL_SELECT = 8

TYPE_CONTAINER

public mixed TYPE_CONTAINER = 17

TYPE_CONTENT_INVENTORY_ENTRY

public mixed TYPE_CONTENT_INVENTORY_ENTRY = 16
public mixed TYPE_MEDIA_GALLERY = 12

TYPE_MENTIONABLE_SELECT

public mixed TYPE_MENTIONABLE_SELECT = 7

TYPE_ROLE_SELECT

public mixed TYPE_ROLE_SELECT = 6

TYPE_SELECT_MENU

Use Component::TYPE_STRING_SELECT

public mixed TYPE_SELECT_MENU = 3

TYPE_SEPARATOR

public mixed TYPE_SEPARATOR = 14

TYPE_STRING_SELECT

public mixed TYPE_STRING_SELECT = 3

TYPE_TEXT_DISPLAY

public mixed TYPE_TEXT_DISPLAY = 10

TYPE_TEXT_INPUT

public mixed TYPE_TEXT_INPUT = 4

TYPE_THUMBNAIL

public mixed TYPE_THUMBNAIL = 11

TYPE_USER_SELECT

public mixed TYPE_USER_SELECT = 5

USAGE

public mixed USAGE = ['Message']

Properties

$id

32 bit integer used as an optional identifier for component.

protected int|null $id

$type

Component type.

protected int $type = \Discord\Builders\Components\Component::TYPE_SECTION

$components

Array of text display components.

private array<string|int, TextDisplay> $components = []

Methods

addComponent()

Adds a text display component to the section.

public addComponent(TextDisplay|string $component) : $this

Text displays can only be used within sections. Use setAccessory() instead for Thumbnail or Button.

Parameters
$component : TextDisplay|string

Text display component to add.

Tags
throws
InvalidArgumentException

Component is not a TextDisplay.

throws
OverflowException

Section exceeds 3 text components.

Return values
$this

getComponents()

Returns all the text components in the section.

public getComponents() : array<string|int, TextDisplay>
Return values
array<string|int, TextDisplay>

getCustomId()

Returns the custom ID of the button.

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

getType()

Retrieves the type of the component.

public getType() : int
Return values
int

jsonSerialize()

{@inheritDoc}

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

new()

Creates a new section.

public static new() : self
Return values
self

setAccessory()

Sets the accessory component of the section.

public setAccessory(Thumbnail|Button $component) : $this

Only Thumbnail or Button components can be used as accessories.

Parameters
$component : Thumbnail|Button

Thumbnail or Button component.

Tags
throws
InvalidArgumentException

Component is not a Thumbnail or Button.

Return values
$this

generateUuid()

Generates a UUID which can be used for component custom IDs.

protected static generateUuid() : string
Return values
string

getId()

The id field is optional and is used to identify components in the response from an interaction that aren't interactive components.

protected getId() : int|null

The id must be unique within the message and is generated sequentially if left empty. Generation of ids won't use another id that exists in the message if you have one defined for another component.

Return values
int|null

        
On this page

Search results