@@ -9,21 +9,20 @@ emojis.
99## Basic usage
1010
1111``` tsx title="src/app/commands/button-example.tsx"
12- import type { ChatInputCommand } from ' commandkit' ;
13- import { ActionRow , Button } from ' commandkit' ;
12+ import { type ChatInputCommand , ActionRow , Button } from ' commandkit' ;
1413
1514export const chatInput: ChatInputCommand = async ({
1615 interaction ,
1716}) => {
18- const button = (
17+ const buttonRow = (
1918 <ActionRow >
20- <Button >Click me!</Button >
19+ <Button customId = " clickme-button " >Click me!</Button >
2120 </ActionRow >
2221 );
2322
2423 await interaction .reply ({
2524 content: " Here's a button:" ,
26- components: [button ],
25+ components: [buttonRow ],
2726 });
2827};
2928```
@@ -33,18 +32,26 @@ export const chatInput: ChatInputCommand = async ({
3332Discord provides several built-in button styles:
3433
3534``` tsx title="src/app/commands/button-styles.tsx"
36- import type { ChatInputCommand } from ' commandkit' ;
37- import { ActionRow , Button } from ' commandkit ' ;
35+ import { type ChatInputCommand , ActionRow , Button } from ' commandkit' ;
36+ import { ButtonStyle } from ' discord.js ' ;
3837
3938export const chatInput: ChatInputCommand = async ({
4039 interaction ,
4140}) => {
4241 const buttons = (
4342 <ActionRow >
44- <Button style = " primary" >Primary</Button >
45- <Button style = " secondary" >Secondary</Button >
46- <Button style = " success" >Success</Button >
47- <Button style = " danger" >Danger</Button >
43+ <Button style = { ButtonStyle .Primary } customId = " primary" >
44+ Primary
45+ </Button >
46+ <Button style = { ButtonStyle .Secondary } customId = " secondary" >
47+ Secondary
48+ </Button >
49+ <Button style = { ButtonStyle .Success } customId = " success" >
50+ Success
51+ </Button >
52+ <Button style = { ButtonStyle .Danger } customId = " danger" >
53+ Danger
54+ </Button >
4855 </ActionRow >
4956 );
5057
@@ -60,15 +67,15 @@ export const chatInput: ChatInputCommand = async ({
6067Link buttons redirect users to external URLs:
6168
6269``` tsx title="src/app/commands/link-button.tsx"
63- import type { ChatInputCommand } from ' commandkit' ;
64- import { ActionRow , Button } from ' commandkit ' ;
70+ import { type ChatInputCommand , ActionRow , Button } from ' commandkit' ;
71+ import { ButtonStyle } from ' discord.js ' ;
6572
6673export const chatInput: ChatInputCommand = async ({
6774 interaction ,
6875}) => {
6976 const linkButton = (
7077 <ActionRow >
71- <Button style = " link " url = " https://discord.com" >
78+ <Button style = { ButtonStyle . Link } url = " https://discord.com" >
7279 Visit Discord
7380 </Button >
7481 </ActionRow >
@@ -86,16 +93,19 @@ export const chatInput: ChatInputCommand = async ({
8693Add emojis to make your buttons more visually appealing:
8794
8895``` tsx title="src/app/commands/emoji-button.tsx"
89- import type { ChatInputCommand } from ' commandkit' ;
90- import { ActionRow , Button } from ' commandkit' ;
96+ import { type ChatInputCommand , ActionRow , Button } from ' commandkit' ;
9197
9298export const chatInput: ChatInputCommand = async ({
9399 interaction ,
94100}) => {
95101 const emojiButton = (
96102 <ActionRow >
97- <Button emoji = " 🎮" >Play Game</Button >
98- <Button emoji = " ⚙️" >Settings</Button >
103+ <Button emoji = " 🎮" customId = " play-game" >
104+ Play Game
105+ </Button >
106+ <Button emoji = " ⚙️" customId = " settings" >
107+ Settings
108+ </Button >
99109 </ActionRow >
100110 );
101111
@@ -111,16 +121,17 @@ export const chatInput: ChatInputCommand = async ({
111121Disable buttons to prevent interaction:
112122
113123``` tsx title="src/app/commands/disabled-button.tsx"
114- import type { ChatInputCommand } from ' commandkit' ;
115- import { ActionRow , Button } from ' commandkit' ;
124+ import { type ChatInputCommand , ActionRow , Button } from ' commandkit' ;
116125
117126export const chatInput: ChatInputCommand = async ({
118127 interaction ,
119128}) => {
120129 const disabledButton = (
121130 <ActionRow >
122- <Button disabled >Cannot Click</Button >
123- <Button >Can Click</Button >
131+ <Button disabled customId = " disabled" >
132+ Cannot Click
133+ </Button >
134+ <Button customId = " enabled" >Can Click</Button >
124135 </ActionRow >
125136 );
126137
@@ -136,8 +147,12 @@ export const chatInput: ChatInputCommand = async ({
136147Handle button interactions with the ` onClick ` prop:
137148
138149``` tsx title="src/app/commands/interactive-button.tsx"
139- import type { ChatInputCommand , OnButtonKitClick } from ' commandkit' ;
140- import { ActionRow , Button } from ' commandkit' ;
150+ import {
151+ type ChatInputCommand ,
152+ type OnButtonKitClick ,
153+ ActionRow ,
154+ Button ,
155+ } from ' commandkit' ;
141156import { MessageFlags } from ' discord.js' ;
142157
143158const handleClick: OnButtonKitClick = async (
@@ -158,7 +173,9 @@ export const chatInput: ChatInputCommand = async ({
158173}) => {
159174 const interactiveButton = (
160175 <ActionRow >
161- <Button onClick = { handleClick } >Click me!</Button >
176+ <Button onClick = { handleClick } customId = " clickme-button" >
177+ Click me!
178+ </Button >
162179 </ActionRow >
163180 );
164181
0 commit comments