Button
        
        extends Interactive
    
    
            
            in package
            
        
    
    
    
Buttons are interactive components that render in messages.
They can be clicked by users, and send an interaction to your app when clicked.
Tags
Table of Contents
Constants
- STYLE_DANGER = 4
- An action with irreversible consequences.
- STYLE_LINK = 5
- Navigates to a URL.
- STYLE_PREMIUM = 6
- Purchase.
- STYLE_PRIMARY = 1
- The most important or recommended action in a group of options.
- STYLE_SECONDARY = 2
- Alternative or supporting actions.
- STYLE_SUCCESS = 3
- Positive confirmation or completion actions.
- TYPE_ACTION_ROW = 1
- Container to display a row of interactive components.
- TYPE_BUTTON = 2
- Button object.
- TYPE_CHANNEL_SELECT = 8
- Select menu for channels.
- TYPE_CHECKPOINT_CARD = 20
- Undocumented.
- TYPE_CONTAINER = 17
- Container that visually groups a set of components.
- TYPE_CONTENT_INVENTORY_ENTRY = 16
- Undocumented.
- TYPE_FILE = 13
- Displays an attached file.
- TYPE_FILE_UPLOAD = 19
- Component for uploading files.
- TYPE_LABEL = 18
- Container associating a label and description with a component.
- TYPE_MEDIA_GALLERY = 12
- Display images and other media.
- TYPE_MENTIONABLE_SELECT = 7
- Select menu for mentionables (users and roles).
- TYPE_ROLE_SELECT = 6
- Select menu for roles.
- TYPE_SECTION = 9
- Container to display text alongside an accessory component.
- TYPE_SELECT_MENU = 3
- TYPE_SEPARATOR = 14
- Component to add vertical padding between other components.
- TYPE_STRING_SELECT = 3
- Select menu for picking from defined text options.
- TYPE_TEXT_DISPLAY = 10
- Markdown text.
- TYPE_TEXT_INPUT = 4
- Text input object.
- TYPE_THUMBNAIL = 11
- Small image that can be used as an accessory.
- TYPE_USER_SELECT = 5
- Select menu for users.
- USAGE = ['Message']
Properties
- $custom_id : string|null
- Custom ID to send with interactive component.
- $disabled : bool|null
- Whether the button is disabled.
- $discord : Discord|null
- Discord instance when the listener is set.
- $emoji : array<string|int, mixed>|null
- Emoji to display on the button.
- $id : int|null
- 32 bit integer used as an optional identifier for component.
- $label : string|null
- Label for the button.
- $listener : callable|null
- Listener for when the button is pressed.
- $sku_id : string|null
- Identifier for a purchasable SKU, only available when using premium-style buttons.
- $style : int
- Style of button.
- $type : int
- Component type.
- $url : string|null
- URL to send as the button. Only for link buttons.
Methods
- __construct() : mixed
- Creates a new button.
- __debugInfo() : array<string|int, mixed>
- __get() : mixed
- Handles dynamic get calls onto the part.
- __set() : void
- Handles dynamic set calls onto the part.
- danger() : self
- Creates a new danger button.
- fromPart() : self
- Creates a new instance of the builder from a given Part.
- getCustomId() : string|null
- Returns the custom ID of the button.
- getEmoji() : array<string|int, mixed>|null
- Returns the emoji display on the button.
- getLabel() : string|null
- Returns the label for the button.
- getSkuId() : string|null
- Returns the SKU ID for the button. Only for premium buttons.
- getStyle() : int
- Returns the style for the button.
- getType() : int
- Retrieves the type of the component.
- getURL() : string|null
- Returns the URL of the button. Only for link buttons.
- isDisabled() : bool
- Returns whether the button is disabled.
- jsonSerialize() : array<string|int, mixed>
- link() : self
- Creates a new link button.
- new() : self
- Creates a new button.
- premium() : self
- Creates a new premium button.
- primary() : self
- Creates a new primary button.
- removeListener() : $this
- Removes the listener from the button.
- secondary() : self
- Creates a new secondary button.
- setCustomId() : $this
- Sets the custom ID of the button.
- setDisabled() : $this
- Sets the button as disabled/not disabled.
- setEmoji() : $this
- Sets the emoji of the button.
- setLabel() : $this
- Sets the label of the button.
- setListener() : $this
- Sets the callable listener for the button. The `$callback` will be called when the button is pressed.
- setSkuId() : $this
- Sets the SKU ID for the button. Only valid for premium buttons.
- setStyle() : $this
- Sets the style of the button.
- setUrl() : $this
- Sets the URL of the button. Only valid for link buttons.
- success() : self
- Creates a new success button.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set mutator present.
- createListener() : callable
- Creates a listener.
- generateUuid() : string
- Generates a UUID which can be used for component custom IDs.
- getId() : int|null
- Retrieves the ID associated with the interactive component.
- getProperty() : mixed
- Gets a property on the parent part.
- 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.
- setProperty() : void
- Sets an property on the parent part.
- studly() : string
- Converts a string to studlyCase.
Constants
STYLE_DANGER
An action with irreversible consequences.
    public
        mixed
    STYLE_DANGER
    = 4
    
    
    
    
STYLE_LINK
Navigates to a URL.
    public
        mixed
    STYLE_LINK
    = 5
    
    
    
    
STYLE_PREMIUM
Purchase.
    public
        mixed
    STYLE_PREMIUM
    = 6
    
    
    
    
STYLE_PRIMARY
The most important or recommended action in a group of options.
    public
        mixed
    STYLE_PRIMARY
    = 1
    
    
    
    
STYLE_SECONDARY
Alternative or supporting actions.
    public
        mixed
    STYLE_SECONDARY
    = 2
    
    
    
    
STYLE_SUCCESS
Positive confirmation or completion actions.
    public
        mixed
    STYLE_SUCCESS
    = 3
    
    
    
    
TYPE_ACTION_ROW
Container to display a row of interactive components.
    public
        mixed
    TYPE_ACTION_ROW
    = 1
    
    
    
    
TYPE_BUTTON
Button object.
    public
        mixed
    TYPE_BUTTON
    = 2
    
    
    
    
TYPE_CHANNEL_SELECT
Select menu for channels.
    public
        mixed
    TYPE_CHANNEL_SELECT
    = 8
    
    
    
    
TYPE_CHECKPOINT_CARD
Undocumented.
    public
        mixed
    TYPE_CHECKPOINT_CARD
    = 20
    
    
    
    
TYPE_CONTAINER
Container that visually groups a set of components.
    public
        mixed
    TYPE_CONTAINER
    = 17
    
    
    
    
TYPE_CONTENT_INVENTORY_ENTRY
Undocumented.
    public
        mixed
    TYPE_CONTENT_INVENTORY_ENTRY
    = 16
    
    
    
    
TYPE_FILE
Displays an attached file.
    public
        mixed
    TYPE_FILE
    = 13
    
    
    
    
TYPE_FILE_UPLOAD
Component for uploading files.
    public
        mixed
    TYPE_FILE_UPLOAD
    = 19
    
    
    
    
TYPE_LABEL
Container associating a label and description with a component.
    public
        mixed
    TYPE_LABEL
    = 18
    
    
    
    
TYPE_MEDIA_GALLERY
Display images and other media.
    public
        mixed
    TYPE_MEDIA_GALLERY
    = 12
    
    
    
    
TYPE_MENTIONABLE_SELECT
Select menu for mentionables (users and roles).
    public
        mixed
    TYPE_MENTIONABLE_SELECT
    = 7
    
    
    
    
TYPE_ROLE_SELECT
Select menu for roles.
    public
        mixed
    TYPE_ROLE_SELECT
    = 6
    
    
    
    
TYPE_SECTION
Container to display text alongside an accessory component.
    public
        mixed
    TYPE_SECTION
    = 9
    
    
    
    
TYPE_SELECT_MENU
Use Component::TYPE_STRING_SELECT
    public
        mixed
    TYPE_SELECT_MENU
    = 3
    
    
    
    
TYPE_SEPARATOR
Component to add vertical padding between other components.
    public
        mixed
    TYPE_SEPARATOR
    = 14
    
    
    
    
TYPE_STRING_SELECT
Select menu for picking from defined text options.
    public
        mixed
    TYPE_STRING_SELECT
    = 3
    
    
    
    
TYPE_TEXT_DISPLAY
Markdown text.
    public
        mixed
    TYPE_TEXT_DISPLAY
    = 10
    
    
    
    
TYPE_TEXT_INPUT
Text input object.
    public
        mixed
    TYPE_TEXT_INPUT
    = 4
    
    
    
    
TYPE_THUMBNAIL
Small image that can be used as an accessory.
    public
        mixed
    TYPE_THUMBNAIL
    = 11
    
    
    
    
TYPE_USER_SELECT
Select menu for users.
    public
        mixed
    TYPE_USER_SELECT
    = 5
    
    
    
    
USAGE
    public
        mixed
    USAGE
    = ['Message']
    
    
    
    
Properties
$custom_id
Custom ID to send with interactive component.
        public
            string|null
    $custom_id
    
        Developer-defined identifier for the button; max 100 characters.
$disabled
Whether the button is disabled.
        protected
            bool|null
    $disabled
    
    
    
    
    
    
$discord
Discord instance when the listener is set.
        protected
            Discord|null
    $discord
    
    
    
    
    
    
$emoji
Emoji to display on the button.
        protected
            array<string|int, mixed>|null
    $emoji
    
    
    
    
    
    
$id
32 bit integer used as an optional identifier for component.
        protected
            int|null
    $id
    
    
    
    
    
    
$label
Label for the button.
        protected
            string|null
    $label
    
    
    
    
    
    
$listener
Listener for when the button is pressed.
        protected
            callable|null
    $listener
    
    
    
    
    
    
$sku_id
Identifier for a purchasable SKU, only available when using premium-style buttons.
        protected
            string|null
    $sku_id
    
    
    
    
    
    
$style
Style of button.
        protected
            int
    $style
     = 1
    
    
    
    
    
$type
Component type.
        protected
            int
    $type
     = \Discord\Builders\Components\Component::TYPE_BUTTON
    
    
    
    
    
$url
URL to send as the button. Only for link buttons.
        protected
            string|null
    $url
    
    
    
    
    
    
Methods
__construct()
Creates a new button.
    public
                    __construct(int $style[, string|null $custom_id = null ]) : mixed
    Parameters
- $style : int
- 
                    Style of the button. 
- $custom_id : string|null = null
- 
                    custom ID of the button. If not given, a UUID will be used 
Tags
__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
Return values
mixed —The value of the attribute.
__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
danger()
Creates a new danger button.
    public
            static        danger([string|null $custom_id = null ]) : self
    Parameters
- $custom_id : string|null = null
- 
                    Custom ID of the button. 
Return values
selffromPart()
Creates a new instance of the builder from a given Part.
    public
            static        fromPart(Part $part) : self
    Parameters
- $part : Part
Return values
selfgetCustomId()
Returns the custom ID of the button.
    public
                    getCustomId() : string|null
    Return values
string|nullgetEmoji()
Returns the emoji display on the button.
    public
                    getEmoji() : array<string|int, mixed>|null
    Return values
array<string|int, mixed>|nullgetLabel()
Returns the label for the button.
    public
                    getLabel() : string|null
    Return values
string|nullgetSkuId()
Returns the SKU ID for the button. Only for premium buttons.
    public
                    getSkuId() : string|null
    Return values
string|nullgetStyle()
Returns the style for the button.
    public
                    getStyle() : int
    Return values
intgetType()
Retrieves the type of the component.
    public
                    getType() : int
    Return values
intgetURL()
Returns the URL of the button. Only for link buttons.
    public
                    getURL() : string|null
    Return values
string|nullisDisabled()
Returns whether the button is disabled.
    public
                    isDisabled() : bool
    Return values
booljsonSerialize()
    public
                    jsonSerialize() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>link()
Creates a new link button.
    public
            static        link(string $url) : self
    Parameters
- $url : string
Return values
selfnew()
Creates a new button.
    public
            static        new(int $style[, string|null $custom_id = null ]) : self
    Parameters
- $style : int
- 
                    Style of the button. 
- $custom_id : string|null = null
- 
                    custom ID of the button. 
Return values
selfpremium()
Creates a new premium button.
    public
            static        premium(string $sku_id) : self
    Parameters
- $sku_id : string
Return values
selfprimary()
Creates a new primary button.
    public
            static        primary([string|null $custom_id = null ]) : self
    Parameters
- $custom_id : string|null = null
- 
                    Custom ID of the button. 
Return values
selfremoveListener()
Removes the listener from the button.
    public
                    removeListener() : $this
    Return values
$thissecondary()
Creates a new secondary button.
    public
            static        secondary([string|null $custom_id = null ]) : self
    Parameters
- $custom_id : string|null = null
- 
                    Custom ID of the button. 
Return values
selfsetCustomId()
Sets the custom ID of the button.
    public
                    setCustomId(string|null $custom_id) : $this
    Parameters
- $custom_id : string|null
Tags
Return values
$thissetDisabled()
Sets the button as disabled/not disabled.
    public
                    setDisabled(bool|null $disabled) : $this
    Parameters
- $disabled : bool|null
Return values
$thissetEmoji()
Sets the emoji of the button.
    public
                    setEmoji(Emoji|string|null $emoji) : $this
    Parameters
- $emoji : Emoji|string|null
- 
                    Emoji to set. nullto clear.
Return values
$thissetLabel()
Sets the label of the button.
    public
                    setLabel(string|null $label) : $this
    Parameters
- $label : string|null
- 
                    Label of the button. Maximum 80 characters. 
Tags
Return values
$thissetListener()
Sets the callable listener for the button. The `$callback` will be called when the button is pressed.
    public
                    setListener(callable|null $callback, Discord $discord[, bool $oneOff = false ][, int|float|null $timeout = null ]) : $this
    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 button is pressed.
To remove the listener, you can pass $callback as null.
The button listener will not persist when the bot restarts.
Parameters
- $callback : callable|null
- 
                    Callback to call when the button is pressed. Will be called with the interaction object. 
- $discord : Discord
- 
                    Discord client. 
- $oneOff : bool = false
- 
                    Whether the listener should be removed after the button is pressed for the first time. 
- $timeout : int|float|null = null
- 
                    Optional timeout in seconds after which the listener will be removed. 
Tags
Return values
$thissetSkuId()
Sets the SKU ID for the button. Only valid for premium buttons.
    public
                    setSkuId(string|null $sku_id) : $this
    Parameters
- $sku_id : string|null
Tags
Return values
$thissetStyle()
Sets the style of the button.
    public
                    setStyle(int $style) : $this
    If the button is originally a link button, the link attribute will be cleared. If the button was changed to a link button, the listener will be cleared.
Parameters
- $style : int
Tags
Return values
$thissetUrl()
Sets the URL of the button. Only valid for link buttons.
    public
                    setUrl(string|null $url) : $this
    Parameters
- $url : string|null
Tags
Return values
$thissuccess()
Creates a new success button.
    public
            static        success([string|null $custom_id = null ]) : self
    Parameters
- $custom_id : string|null = null
- 
                    Custom ID of the button. 
Return values
selfcheckForGetMutator()
Checks if there is a get mutator present.
    protected
                    checkForGetMutator(string $key) : string|false
    Parameters
- $key : string
- 
                    The property name to check. 
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
    protected
                    checkForSetMutator(string $key) : string|false
    Parameters
- $key : string
- 
                    The property name to check. 
Return values
string|false —Either a string if it is a method or false.
createListener()
Creates a listener.
    protected
                    createListener(callable $callback[, bool $oneOff = false ][, int|float|null $timeout = null ]) : callable
    Parameters
- $callback : callable
- 
                    The callback to execute when the interaction occurs. 
- $oneOff : bool = false
- 
                    Whether the listener should be removed after one use. 
- $timeout : int|float|null = null
- 
                    Optional timeout in seconds after which the listener will be removed. 
Return values
callable —The listener closure.
generateUuid()
Generates a UUID which can be used for component custom IDs.
    protected
            static        generateUuid() : string
    Return values
stringgetId()
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|nullgetProperty()
Gets a property on the parent part.
    protected
                    getProperty(string $key) : mixed
    Parameters
- $key : string
- 
                    The name of the property. 
Tags
Return values
mixed —Either the property if it exists or void.
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
selfsetProperty()
Sets an property on the parent part.
    protected
                    setProperty(string $key, mixed $value) : void
    Parameters
- $key : string
- 
                    The name of the property. 
- $value : mixed
- 
                    The value of the property. 
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. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
- 
                    The string to convert.