Button - Bilal2453/discordia-components GitHub Wiki

extends Component

Represents a Component of type Button. Buttons are interactive message components that when pressed Discord fires an interactionCreate event. The Button class contains methods to retrieve and set different attributes of a Button.

For accepted data fields see Button-Resolvable.

General rules you should follow:

  1. Link buttons must have url, and cannot have id. And vise versa.
  2. Link buttons do not fire interactionCreate; meaning you cannot listen to a link button to know when it is pressed.
  3. An Action Row can contain up to 5 buttons only, and a button can never be in the same row as a select menu.

Constructor

Button(data, actionRow)

Parameter Type Optional
data Button-Resolvable
actionRow number

Properties Inherited From Component

Name Type Description
actionRow number The Action Row this component is using.
disabled boolean Whether the current component is disabled or not.
id string The component custom_id. Nil for some components such as Link Buttons.
type number The component type. See componentType enumeration for further info.

Methods Inherited From Component

disable()

Sets the disabled field to true.

Returns self.

This method only operates on data in memory.

Returns: Component


enable()

Sets the disabled field to false.

Returns self.

This method only operates on data in memory.

Returns: Component


get(property)

Parameter Type
property string

Returns the value of the provided property name.

This method only operates on data in memory.

Returns: any


raw()

Returns a table value of what the raw value Discord would accept is like based on assumptions of the current component's field names.

By design, user should never need to use this method.

This method only operates on data in memory.

Returns: table


set(property, value)

Parameter Type Optional
property string/table
value any

Sets the provided field(s) value. If property is a table, value is ignored; the key of an entry is treated as the field name, and its value is the field's value. Otherwise if property is a string, value is required. Keep in mind this will validate the inputs and error if not valid.

This method only operates on data in memory.

Returns: Component


Methods

emoji(emoji, id, animated)

Parameter Type Optional
emoji Emoji-Resolvable/string
id Emoji-ID-Resolvable
animated boolean

Sets an emoji field for the Button. emoji can be a string to indicate emoji name in which case id and animated parameters will be available for use. For Unicode emotes you only need to set name field to the desired Unicode.

Returns self.

This method only operates on data in memory.

Returns: Button


label(label)

Parameter Type
label string

Sets the label field of the Button. Must be in the range 0 < label < 81.

Returns self.

This method only operates on data in memory.

Returns: Button


style(style)

Parameter Type
style string/number

Sets the style attribute of the Button. See buttonStyle enumeration for acceptable style values.

Returns self.

This method only operates on data in memory.

Returns: Button


url(url)

Parameter Type
url string

Sets the url for a Link Button. If Button's style was not link it will be forcibly changed to that. Keep in mind, a Link Button cannot have an id.

Returns self.

This method only operates on data in memory.

Returns: Button