DiscordPHP Documentation

ChannelSelect extends SelectMenu
in package

Select menu for channels.

Tags
link
https://discord.com/developers/docs/interactions/message-components#select-menus
since
10.0.0
@property

?int|null $id Optional identifier for component.

@property

?int[]|null $channel_types List of channel types to include in the channel select component.

@property

?string|null $placeholder Placeholder text if nothing is selected; max 150 characters.

@property

?array|null $default_values List of default values for auto-populated select menu components.

@property

?int|null $min_values Minimum number of items that must be chosen (defaults to 1); min 0, max 25.

@property

?int|null $max_values Maximum number of items that can be chosen (defaults to 1); max 25.

@property

?bool|null $disabled Whether select menu is disabled (defaults to false).

Table of Contents

Constants

TYPE_ACTION_ROW  = 1
TYPE_BUTTON  = 2
TYPE_CHANNEL_SELECT  = 8
TYPE_CONTAINER  = 17
TYPE_CONTENT_INVENTORY_ENTRY  = 16
TYPE_FILE  = 13
TYPE_LABEL  = 18
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', 'Modal']

Properties

$custom_id  : string
Custom ID to identify the select menu.
$channel_types  : array<string|int, int>
List of channel types to include.
$default_values  : array<string|int, mixed>|null
List of default values for auto-populated select menu components; number of default values must be in the range defined by min_values and max_values.
$disabled  : bool|null
Whether the select menu should be disabled.
$discord  : Discord|null
Discord instance when the listener is set.
$id  : int|null
32 bit integer used as an optional identifier for component.
$listener  : callable|null
Callback used to listen for `INTERACTION_CREATE` events.
$max_values  : int|null
Maximum number of options that must be selected.
$min_values  : int|null
Minimum number of options that must be selected.
$options  : array<string|int, mixed>|null
Specified choices in a select menu (only required and available for string selects (type 3); max 25.
$placeholder  : string|null
Placeholder string to display if nothing is selected. Maximum 150 characters.
$required  : bool|null
Whether the select menu is required. Defaults to true. (Modal only).
$type  : int
Component type.

Methods

__construct()  : mixed
Creates a new select menu.
getChannelTypes()  : array<string|int, mixed>
Returns the array of channel types that the select menu has.
getCustomId()  : string
Returns the Custom ID of the select menu.
getDefaultValues()  : array<string|int, mixed>|null
Returns the default values of the select menu.
getMaxValues()  : int|null
Returns the maximum number of options that must be selected.
getMinValues()  : int|null
Returns the minimum number of options that must be selected.
getOptions()  : array<string|int, mixed>|null
Returns the options of the select menu.
getPlaceholder()  : string|null
Returns the placeholder string of the select menu.
getType()  : int
Retrieves the type of the component.
isDisabled()  : bool|null
Returns whether the select menu is disabled.
jsonSerialize()  : array<string|int, mixed>
new()  : static
Creates a new select menu.
removeListener()  : $this
Removes the listener from the button.
setChannelTypes()  : $this
Set the channel types of the select menu.
setCustomId()  : $this
Sets the custom ID for the select menu.
setDefaultValues()  : self
setDisabled()  : $this
Sets the select menus disabled state. (Message only).
setListener()  : $this
Sets the callable listener for the select menu. The `$callback` function will be called when the selection of the menu is changed.
setMaxValues()  : $this
Sets the maximum number of options which must be chosen.
setMinValues()  : $this
Sets the minimum number of options which must be chosen.
setOptions()  : $this
Specified choices in a select menu (only required and available for string selects (type 3); max 25.
setPlaceholder()  : $this
Sets the placeholder string to display if nothing is selected.
setRequired()  : $this
Set if this component is required to be filled, default false. (Modal only).
setType()  : string
Sets the type for the select menu.
createListener()  : callable
Creates a listener callback for handling select menu interactions.
generateUuid()  : string
Generates a UUID which can be used for component custom IDs.
getId()  : int|null
Retrieves the ID associated with the interactive component.
setId()  : self
The id field is optional and is used to identify components in the response from an interaction. 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. Sending components with an id of 0 is allowed but will be treated as empty and replaced by the API. 32 bit integer used as an optional identifier for component.

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

Properties

$custom_id

Custom ID to identify the select menu.

public string $custom_id

ID for the select menu; max 100 characters.

$channel_types

List of channel types to include.

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

$default_values

List of default values for auto-populated select menu components; number of default values must be in the range defined by min_values and max_values.

protected array<string|int, mixed>|null $default_values

$disabled

Whether the select menu should be disabled.

protected bool|null $disabled

$discord

Discord instance when the listener is set.

protected Discord|null $discord

$id

32 bit integer used as an optional identifier for component.

protected int|null $id

$listener

Callback used to listen for `INTERACTION_CREATE` events.

protected callable|null $listener

$max_values

Maximum number of options that must be selected.

protected int|null $max_values

Default 1, maximum 25.

$min_values

Minimum number of options that must be selected.

protected int|null $min_values

Default 1, minimum 0, maximum 25.

$options

Specified choices in a select menu (only required and available for string selects (type 3); max 25.

protected array<string|int, mixed>|null $options

$placeholder

Placeholder string to display if nothing is selected. Maximum 150 characters.

protected string|null $placeholder

$required

Whether the select menu is required. Defaults to true. (Modal only).

protected bool|null $required

$type

Component type.

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

Methods

__construct()

Creates a new select menu.

public __construct(string|null $custom_id) : mixed
Parameters
$custom_id : string|null

The custom ID of the select menu. If not given, a UUID will be used

getChannelTypes()

Returns the array of channel types that the select menu has.

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

getCustomId()

Returns the Custom ID of the select menu.

public getCustomId() : string
Return values
string

getDefaultValues()

Returns the default values of the select menu.

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

getMaxValues()

Returns the maximum number of options that must be selected.

public getMaxValues() : int|null
Return values
int|null

getMinValues()

Returns the minimum number of options that must be selected.

public getMinValues() : int|null
Return values
int|null

getOptions()

Returns the options of the select menu.

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

getPlaceholder()

Returns the placeholder string of the select menu.

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

getType()

Retrieves the type of the component.

public getType() : int
Return values
int

isDisabled()

Returns whether the select menu is disabled.

public isDisabled() : bool|null
Return values
bool|null

jsonSerialize()

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

new()

Creates a new select menu.

public static new([string|null $custom_id = null ]) : static
Parameters
$custom_id : string|null = null

The custom ID of the select menu.

Return values
static

removeListener()

Removes the listener from the button.

public removeListener() : $this
Return values
$this

setCustomId()

Sets the custom ID for the select menu.

public setCustomId(string $custom_id) : $this
Parameters
$custom_id : string
Tags
throws
LengthException

If the custom ID is longer than 100 characters.

Return values
$this

setDefaultValues()

public setDefaultValues(array<string|int, mixed>|null $default_values) : self
Parameters
$default_values : array<string|int, mixed>|null
Return values
self

setDisabled()

Sets the select menus disabled state. (Message only).

public setDisabled([bool|null $disabled = true ]) : $this
Parameters
$disabled : bool|null = true
Return values
$this

setListener()

Sets the callable listener for the select menu. The `$callback` function will be called when the selection of the menu is changed.

public setListener(callable $callback, Discord $discord[, bool $oneOff = false ][, int|float|null $timeout = null ]) : $this

The callback function is called with the Interaction object as well as a Collection of selected options.

If you do not respond to or acknowledge the Interaction, it will be acknowledged for you. Note that if you intend to respond to or acknowledge the interaction inside a promise, you should return a promise that resolves after you respond or acknowledge.

The callback will only be called once with the $oneOff parameter set to true. This can be changed to false, and the callback will be called each time the selection is changed. To remove the listener, you can pass $callback as null.

The select menu listener will not persist when the bot restarts.

Parameters
$callback : callable

Callback to call when the selection is changed. Will be called with the interaction object and collection of options.

$discord : Discord

Discord client.

$oneOff : bool = false

Whether the listener should be removed after the selection is changed for the first time.

$timeout : int|float|null = null
Tags
todo

setListener callback return for each type.

Return values
$this

setMaxValues()

Sets the maximum number of options which must be chosen.

public setMaxValues(int|null $max_values) : $this
Parameters
$max_values : int|null

Default 1 and maximum 25. null to set as default.

Tags
throws
LengthException
Return values
$this

setMinValues()

Sets the minimum number of options which must be chosen.

public setMinValues(int|null $min_values) : $this
Parameters
$min_values : int|null

Default 1, minimum 0 and maximum 25. null to set as default.

Tags
throws
LengthException
Return values
$this

setOptions()

Specified choices in a select menu (only required and available for string selects (type 3); max 25.

public setOptions(array<string|int, mixed> $options) : $this
Parameters
$options : array<string|int, mixed>
Tags
throws
InvalidArgumentException

If the select menu type is not TYPE_STRING_SELECT.

Return values
$this

setPlaceholder()

Sets the placeholder string to display if nothing is selected.

public setPlaceholder(string|null $placeholder) : $this
Parameters
$placeholder : string|null

Maximum 150 characters. null to clear placeholder.

Tags
throws
LengthException
Return values
$this

setRequired()

Set if this component is required to be filled, default false. (Modal only).

public setRequired([bool|null $required = null ]) : $this
Parameters
$required : bool|null = null
Return values
$this

setType()

Sets the type for the select menu.

public setType(int $type) : string

(text: 3, user: 5, role: 6, mentionable: 7, channels: 8).

Parameters
$type : int
Tags
throws
InvalidArgumentException
Return values
string

createListener()

Creates a listener callback for handling select menu interactions.

protected createListener(callable $callback[, bool $oneOff = false ][, int|float|null $timeout = null ]) : callable
Parameters
$callback : callable

The callback to execute when the interaction is received. If the select menu has options, the callback receives ($interaction, $options), otherwise just ($interaction).

$oneOff : bool = false

Whether the listener should be removed after being triggered once.

$timeout : int|float|null = null

Optional timeout in seconds after which the listener will be removed.

Return values
callable

The listener closure to be registered for interaction events.

generateUuid()

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

protected static generateUuid() : string
Return values
string

getId()

Retrieves the ID associated with the interactive component.

protected getId() : int|null

Always returns null as this component does not have an ID.

Return values
int|null

setId()

The id field is optional and is used to identify components in the response from an interaction. 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. Sending components with an id of 0 is allowed but will be treated as empty and replaced by the API. 32 bit integer used as an optional identifier for component.

protected setId([string|null $id = null ]) : self
Parameters
$id : string|null = null

32 bit integer used as an optional identifier for component.

Return values
self

        
On this page

Search results