|
| 1 | +--- |
| 2 | +title: ButtonKit |
| 3 | +description: No description provided |
| 4 | +--- |
| 5 | + |
| 6 | +## ButtonKit extends ButtonBuilder |
| 7 | + |
| 8 | +```typescript |
| 9 | +ButtonKit(data); |
| 10 | +``` |
| 11 | + |
| 12 | +| Parameter | Type | Optional | |
| 13 | +| --------- | ------------------------------------------------------------- | -------- | |
| 14 | +| data | Partial\<ButtonComponentData> \| Partial\<APIButtonComponent> | ✅ | |
| 15 | + |
| 16 | +## Properties |
| 17 | + |
| 18 | +### public data: any |
| 19 | + |
| 20 | +The API data associated with this component. |
| 21 | + |
| 22 | +## Methods |
| 23 | + |
| 24 | +### public dispose(): ButtonKit |
| 25 | + |
| 26 | +- [Source](https://github.com/underctrl-io/commandkit/blob/c462cc3d6f765a7ee19e33a651f0f2f4666b111b/packages/commandkit/src/components/ButtonKit.ts#L165) |
| 27 | + |
| 28 | +### public onClick(handler, data?): this |
| 29 | + |
| 30 | +Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used. |
| 31 | +If unused, this expires after 24 hours or custom time if specified. |
| 32 | + |
| 33 | +```ts |
| 34 | +const button = new ButtonKit() |
| 35 | + .setLabel('Click me') |
| 36 | + .setStyle(ButtonStyle.Primary) |
| 37 | + .setCustomId('click_me'); |
| 38 | + |
| 39 | +const row = new ActionRowBuilder().addComponents(button); |
| 40 | + |
| 41 | +const message = await channel.send({ |
| 42 | + content: 'Click the button', |
| 43 | + components: [row], |
| 44 | +}); |
| 45 | + |
| 46 | +button.onClick( |
| 47 | + async (interaction) => { |
| 48 | + await interaction.reply('You clicked me!'); |
| 49 | + }, |
| 50 | + { message }, |
| 51 | +); |
| 52 | + |
| 53 | +// Remove onClick handler and destroy the interaction collector |
| 54 | +button.onClick(null); |
| 55 | +``` |
| 56 | + |
| 57 | +| Parameter | Type | Optional | Description | |
| 58 | +| --------- | -------------------------------------------------------------- | -------- | ----------------------------------------------------- | |
| 59 | +| handler | CommandKitButtonBuilderInteractionCollectorDispatch | ❌ | The handler to run when the button is clicked | |
| 60 | +| data | CommandKitButtonBuilderInteractionCollectorDispatchContextData | ✅ | The context data to use for the interaction collector | |
| 61 | + |
| 62 | +- [Source](https://github.com/underctrl-io/commandkit/blob/c462cc3d6f765a7ee19e33a651f0f2f4666b111b/packages/commandkit/src/components/ButtonKit.ts#L74) |
| 63 | + |
| 64 | +### public onEnd(handler): this |
| 65 | + |
| 66 | +| Parameter | Type | Optional | |
| 67 | +| --------- | ---------------------------- | -------- | |
| 68 | +| handler | CommandKitButtonBuilderOnEnd | ❌ | |
| 69 | + |
| 70 | +- [Source](https://github.com/underctrl-io/commandkit/blob/c462cc3d6f765a7ee19e33a651f0f2f4666b111b/packages/commandkit/src/components/ButtonKit.ts#L98) |
| 71 | + |
| 72 | +### public setCustomId(customId): this |
| 73 | + |
| 74 | +Sets the custom id for this button. |
| 75 | + |
| 76 | +| Parameter | Type | Optional | Description | |
| 77 | +| --------- | ------------------------------------------------------------------------------------------------- | -------- | -------------------- | |
| 78 | +| customId | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | ❌ | The custom id to use | |
| 79 | + |
| 80 | +### public setDisabled(disabled?): this |
| 81 | + |
| 82 | +Sets whether this button is disabled. |
| 83 | + |
| 84 | +| Parameter | Type | Optional | Description | |
| 85 | +| --------- | --------------------------------------------------------------------------------------------------- | -------- | ------------------------------ | |
| 86 | +| disabled | [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | ✅ | Whether to disable this button | |
| 87 | + |
| 88 | +### public setEmoji(emoji): this |
| 89 | + |
| 90 | +Sets the emoji to display on this button. |
| 91 | + |
| 92 | +| Parameter | Type | Optional | Description | |
| 93 | +| --------- | ------------------------ | -------- | ---------------- | |
| 94 | +| emoji | ComponentEmojiResolvable | ❌ | The emoji to use | |
| 95 | + |
| 96 | +### public setLabel(label): this |
| 97 | + |
| 98 | +Sets the label for this button. |
| 99 | + |
| 100 | +| Parameter | Type | Optional | Description | |
| 101 | +| --------- | ------------------------------------------------------------------------------------------------- | -------- | ---------------- | |
| 102 | +| label | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | ❌ | The label to use | |
| 103 | + |
| 104 | +### public setSKUId(skuId): this |
| 105 | + |
| 106 | +Sets the SKU id that represents a purchasable SKU for this button. |
| 107 | + |
| 108 | +| Parameter | Type | Optional | Description | |
| 109 | +| --------- | ------------------------------------------------------------------------------------------------- | -------- | ----------------- | |
| 110 | +| skuId | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | ❌ | The SKU id to use | |
| 111 | + |
| 112 | +### public setStyle(style): this |
| 113 | + |
| 114 | +Sets the style of this button. |
| 115 | + |
| 116 | +| Parameter | Type | Optional | Description | |
| 117 | +| --------- | ----------- | -------- | ---------------- | |
| 118 | +| style | ButtonStyle | ❌ | The style to use | |
| 119 | + |
| 120 | +### public setURL(url): this |
| 121 | + |
| 122 | +Sets the URL for this button. |
| 123 | + |
| 124 | +| Parameter | Type | Optional | Description | |
| 125 | +| --------- | ------------------------------------------------------------------------------------------------- | -------- | -------------- | |
| 126 | +| url | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | ❌ | The URL to use | |
| 127 | + |
| 128 | +### public toJSON(): APIButtonComponent |
| 129 | + |
| 130 | +ComponentBuilder.toJSON |
| 131 | + |
| 132 | +### public static from(other): ButtonBuilder |
| 133 | + |
| 134 | +| Parameter | Type | Optional | |
| 135 | +| --------- | ------------------ | ---------------------------------- | --- | |
| 136 | +| other | APIButtonComponent | JSONEncodable\<APIButtonComponent> | ❌ | |
0 commit comments