You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/pages/guide/buttonkit.mdx
+41-7Lines changed: 41 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ButtonKit is an enhanced version of the native Discord.js [`ButtonBuilder`](http
6
6
7
7
It is not recommended to use this to listen for button clicks forever since it creates collectors. For that purpose, it's recommended to use a regular "interactionCreate" event listener.
8
8
9
-
## Usage
9
+
## Handle button clicks
10
10
11
11
<Tabsitems={['CommonJS', 'ESM', 'TypeScript']}>
12
12
<Tabs.Tab>
@@ -98,7 +98,7 @@ In the above example, you may notice how similar `ButtonKit` is to the native Di
98
98
99
99
Here's an empty `onClick` method without any arguments:
100
100
101
-
```js
101
+
```js copy
102
102
constmyButton=newButtonKit()
103
103
.setCustomId('custom_button')
104
104
.setLabel('Click me!')
@@ -109,15 +109,15 @@ myButton.onClick();
109
109
110
110
The first argument required by this function is your handler function which will acknowledge button clicks (interactions) handled by ButtonKit. You can handle them like so:
111
111
112
-
```js
112
+
```js copy
113
113
myButton.onClick((buttonInteraction) => {
114
114
buttonInteraction.reply('You clicked a button!');
115
115
});
116
116
```
117
117
118
-
However, the code above won't actually work since ButtonKit doesn't have any idea where it's supposed to specifically listen button clicks from. To fix that, you need to pass in a second argumentwhich houses all the collector options. The `message` property is the message that ButtonKit will use to listen for button clicks.
118
+
However, the code above won't actually work since ButtonKit doesn't have any idea where it's supposed to specifically listen button clicks from. To fix that, you need to pass in a second argument, also known as your [options](/guide/buttonkit#buttonkit-onclick-options)which houses all the collector configuration. The `message` property is the message that ButtonKit will use to listen for button clicks.
This feature is currently only available in the [development
175
+
version](/guide/installation#development-version)
176
+
</Callout>
177
+
178
+
When setting up an `onClick()` method using ButtonKit, you may also want to run some code after the collector ends running. The default timeout is 1 day, but you can modify this in [onClickOptions#time](/guide/buttonkit#time-optional). To handle when the collector ends, you can setup an `onEnd()` method like this:
0 commit comments