Skip to content

ButtonBuilder

ButtonBuilder

The Button class is a class that represents a button.

Kind: global class

new ButtonBuilder()

The function takes an object as an argument, and then assigns the object’s properties to the function’s properties.

buttonBuilder.setLabel(label)

This function sets the label property of the component to the value of the label parameter.

Kind: instance method of ButtonBuilder
Access: public

ParamTypeDescription
labelstringThe label of the button.

buttonBuilder.setEmoji(emoji)

This function sets the emoji property of the component to the emoji passed in as an argument.

Kind: instance method of ButtonBuilder
Access: public

ParamTypeDescription
emojiObjectThe emoji to set.

buttonBuilder.setDisabled() ⇒

setDisabled() sets the disabled property to true and returns the object.

Kind: instance method of ButtonBuilder
Returns: The object itself.

buttonBuilder.setStyle(style) ⇒

setStyle is a function that takes a parameter called style and sets the value of the style property of the object that called it to the value of the style parameter.

The return this statement at the end of the function is a common pattern in JavaScript. It allows us to chain function calls together. For example, we can call setStyle and then immediately call setColor like this:

Kind: instance method of ButtonBuilder
Returns: The object itself.
Access: public

ParamTypeDescription
stylenumberThe style to apply to the element.

buttonBuilder.setUrl(url)

This function sets the url property of the component to the url passed in as an argument.

Kind: instance method of ButtonBuilder
Access: public

ParamTypeDescription
urlstringThe URL of the page to be loaded.

buttonBuilder.setCustomId(customid)

This function sets the customid property of the component to the value of the customid parameter.

Kind: instance method of ButtonBuilder
Access: public

ParamTypeDescription
customidstringThe custom id of the user.

buttonBuilder.toJSON() ⇒

It returns an object with the properties of the button.

Kind: instance method of ButtonBuilder
Returns: An object with the properties type, custom_id, style, label, emoji, disabled, and url.
Access: public

ButtonBuilder.transformFields(fields) ⇒

This function takes an object with properties named ‘emoji’, ‘text’, ‘url’, ‘customid’, ‘style’, and ‘disabled’, and returns an object with the same properties, but with the names changed to ‘emoji’, ‘label’, ‘url’, ‘customid’, ‘style’, and ‘disabled’.

Kind: static method of ButtonBuilder
Returns: The transformFields function is returning an object with the following properties: emoji, label, url, customid, style, and disabled.
Access: public

ParamDescription
fieldsThe fields object that is passed to the component.