Search...

ButtonBuilder

export declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent> 
export declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent> 
Represents a button component

Extends

ComponentBuilder<APIButtonComponent>

constructor(data?)

Creates a new button from API data
Example
Creating a button from an API data object
const button = new ButtonBuilder({
	custom_id: 'a cool button',
	style: ButtonStyle.Primary,
	label: 'Click Me',
	emoji: {
		name: 'smile',
		id: '123456789012345678',
	},
});
const button = new ButtonBuilder({
	custom_id: 'a cool button',
	style: ButtonStyle.Primary,
	label: 'Click Me',
	emoji: {
		name: 'smile',
		id: '123456789012345678',
	},
});
Example
Creating a button using setters and API data
const button = new ButtonBuilder({
	style: ButtonStyle.Secondary,
	label: 'Click Me',
})
	.setEmoji({ name: '🙂' })
	.setCustomId('another cool button');
const button = new ButtonBuilder({
	style: ButtonStyle.Secondary,
	label: 'Click Me',
})
	.setEmoji({ name: '🙂' })
	.setCustomId('another cool button');
NameTypeOptionalDescription
dataPartial<APIButtonComponent>YesThe API data to create this button with
Readonly

data

:

Partial<DataType>

The API data associated with this component
Inherited from ComponentBuilder

setCustomId(customId)

:

this

Sets the custom id for this button
Remarks
This method is only applicable to buttons that are not using the Link button style.
NameTypeOptionalDescription
customIdstringNoThe custom id to use for this button

setDisabled(disabled?)

:

this

Sets whether this button is disabled
NameTypeOptionalDescription
disabledbooleanYesWhether to disable this button

setEmoji(emoji)

:

this

Sets the emoji to display on this button
NameTypeOptionalDescription
emojiAPIMessageComponentEmojiNoThe emoji to display on this button

setLabel(label)

:

this

Sets the label for this button
NameTypeOptionalDescription
labelstringNoThe label to display on this button

setStyle(style)

:

this

Sets the style of this button
NameTypeOptionalDescription
styleButtonStyleNoThe style of the button

setURL(url)

:

this

Sets the URL for this button
Remarks
This method is only available to buttons using the Link button style. Only three types of URL schemes are currently supported: https://, http:// and discord://
NameTypeOptionalDescription
urlstringNoThe URL to open when this button is clicked

toJSON()

:

APIButtonComponent

Serializes this component to an API-compatible JSON object
Remarks
This method runs validations on the data before serializing it. As such, it may throw an error if the data is invalid.