Preview environment
class ButtonBuilder
extends
ComponentBuilder<APIButtonComponent>export declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent>
A builder that creates API-compatible JSON data for buttons.
Constructors
data?: Partial<APIButtonComponent>) constructor(
data?: Partial<APIButtonComponent>
Creates a new button from API data.
Examples:Creating a button from an API data object:Creating a button using setters and API data:
const button = new ButtonBuilder({
custom_id: 'a cool button',
style: ButtonStyle.Primary,
label: 'Click Me',
emoji: {
name: 'smile',
id: '123456789012345678',
},
});
const button = new ButtonBuilder({
style: ButtonStyle.Secondary,
label: 'Click Me',
})
.setEmoji({ name: '🙂' })
.setCustomId('another cool button');
readonlyPartial<APIButtonComponent> data :
The API data associated with this component.
Inherited from: ComponentBuilder
Clears the id of this component, defaulting to a default incremented id.
Inherited from: ComponentBuilder
setCustomIdcustomId: string) : this (
customId: string
Sets the custom id for this button.
setDisableddisabled?: boolean) : this (
disabled?: boolean
Sets whether this button is disabled.
setEmojiemoji: APIMessageComponentEmoji) : this (
emoji: APIMessageComponentEmoji
Sets the emoji to display on this button.
setIdid: number) : this (
id: number
Sets the id (not the custom id) for this component.
Inherited from: ComponentBuilder
setLabellabel: string) : this (
label: string
Sets the label for this button.
setSKUIdskuId: Snowflake) : this (
skuId: Snowflake
Sets the SKU id that represents a purchasable SKU for this button.
setStylestyle: ButtonStyle) : this (
style: ButtonStyle
Sets the style of this button.
setURLurl: string) : this (
url: string
Sets the URL for this button.
toJSONAPIButtonComponent () :
Serializes this builder to API-compatible JSON data.