@@ -9,21 +9,20 @@ emojis.
9
9
## Basic usage
10
10
11
11
``` 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' ;
14
13
15
14
export const chatInput: ChatInputCommand = async ({
16
15
interaction ,
17
16
}) => {
18
- const button = (
17
+ const buttonRow = (
19
18
<ActionRow >
20
- <Button >Click me!</Button >
19
+ <Button customId = " clickme-button " >Click me!</Button >
21
20
</ActionRow >
22
21
);
23
22
24
23
await interaction .reply ({
25
24
content: " Here's a button:" ,
26
- components: [button ],
25
+ components: [buttonRow ],
27
26
});
28
27
};
29
28
```
@@ -33,18 +32,26 @@ export const chatInput: ChatInputCommand = async ({
33
32
Discord provides several built-in button styles:
34
33
35
34
``` 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 ' ;
38
37
39
38
export const chatInput: ChatInputCommand = async ({
40
39
interaction ,
41
40
}) => {
42
41
const buttons = (
43
42
<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 >
48
55
</ActionRow >
49
56
);
50
57
@@ -60,15 +67,15 @@ export const chatInput: ChatInputCommand = async ({
60
67
Link buttons redirect users to external URLs:
61
68
62
69
``` 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 ' ;
65
72
66
73
export const chatInput: ChatInputCommand = async ({
67
74
interaction ,
68
75
}) => {
69
76
const linkButton = (
70
77
<ActionRow >
71
- <Button style = " link " url = " https://discord.com" >
78
+ <Button style = { ButtonStyle . Link } url = " https://discord.com" >
72
79
Visit Discord
73
80
</Button >
74
81
</ActionRow >
@@ -86,16 +93,19 @@ export const chatInput: ChatInputCommand = async ({
86
93
Add emojis to make your buttons more visually appealing:
87
94
88
95
``` 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' ;
91
97
92
98
export const chatInput: ChatInputCommand = async ({
93
99
interaction ,
94
100
}) => {
95
101
const emojiButton = (
96
102
<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 >
99
109
</ActionRow >
100
110
);
101
111
@@ -111,16 +121,17 @@ export const chatInput: ChatInputCommand = async ({
111
121
Disable buttons to prevent interaction:
112
122
113
123
``` 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' ;
116
125
117
126
export const chatInput: ChatInputCommand = async ({
118
127
interaction ,
119
128
}) => {
120
129
const disabledButton = (
121
130
<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 >
124
135
</ActionRow >
125
136
);
126
137
@@ -136,8 +147,12 @@ export const chatInput: ChatInputCommand = async ({
136
147
Handle button interactions with the ` onClick ` prop:
137
148
138
149
``` 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' ;
141
156
import { MessageFlags } from ' discord.js' ;
142
157
143
158
const handleClick: OnButtonKitClick = async (
@@ -158,7 +173,9 @@ export const chatInput: ChatInputCommand = async ({
158
173
}) => {
159
174
const interactiveButton = (
160
175
<ActionRow >
161
- <Button onClick = { handleClick } >Click me!</Button >
176
+ <Button onClick = { handleClick } customId = " clickme-button" >
177
+ Click me!
178
+ </Button >
162
179
</ActionRow >
163
180
);
164
181
0 commit comments