diff --git a/apps/docs/pages/guide/buttonkit.mdx b/apps/docs/pages/guide/buttonkit.mdx index 5c34658..94655a7 100644 --- a/apps/docs/pages/guide/buttonkit.mdx +++ b/apps/docs/pages/guide/buttonkit.mdx @@ -195,3 +195,30 @@ myButton message.edit({ components: [row] }); }); ``` + +## Dispose button collector + + + This feature is currently only available in the [development + version](/guide/installation#development-version). + + +To dispose the button collector, you can make use of the `dispose` method. By disposing the collector like this, your `onEnd` handler (if any) will be called automatically. + +```js copy {15} +myButton + .onClick( + (buttonInteraction) => { + buttonInteraction.reply('You clicked a button!'); + }, + { message }, + ) + .onEnd(() => { + console.log('Button collector ended.'); + + myButton.setDisabled(true); + message.edit({ components: [row] }); + }); + +myButton.dispose(); +``` diff --git a/packages/commandkit/src/components/ButtonKit.ts b/packages/commandkit/src/components/ButtonKit.ts index 9842add..c23bf0e 100644 --- a/packages/commandkit/src/components/ButtonKit.ts +++ b/packages/commandkit/src/components/ButtonKit.ts @@ -149,6 +149,12 @@ export class ButtonKit extends ButtonBuilder { }); } + public dispose() { + this.#destroyCollector(); + this.#onEndHandler?.(); + return this; + } + #destroyCollector() { this.#collector?.stop('end'); this.#collector?.removeAllListeners();