@@ -9,7 +9,10 @@ import {
99 getCommandKit ,
1010 getContext ,
1111} from '../../context/async-context' ;
12- import { EventInterceptorContextData } from '../common/EventInterceptor' ;
12+ import {
13+ EventInterceptorContextData ,
14+ EventInterceptorErrorHandler ,
15+ } from '../common/EventInterceptor' ;
1316
1417export type ModalKitPredicate = (
1518 interaction : ModalSubmitInteraction ,
@@ -34,6 +37,7 @@ export type OnModalKitEnd = CommandKitModalBuilderOnEnd;
3437 */
3538export type CommandKitModalBuilderInteractionCollectorDispatch = (
3639 interaction : ModalSubmitInteraction ,
40+ context : ModalKit ,
3741) => Awaitable < void > ;
3842
3943export type CommandKitModalBuilderOnEnd = ( reason : string ) => Awaitable < void > ;
@@ -46,8 +50,9 @@ export class ModalKit extends ModalBuilder {
4650 null ;
4751 #contextData: CommandKitModalBuilderInteractionCollectorDispatchContextData | null =
4852 {
49- autoReset : true ,
53+ autoReset : false ,
5054 time : 5 * 60 * 1000 ,
55+ once : true ,
5156 } ;
5257 #unsub: ( ( ) => void ) | null = null ;
5358
@@ -123,6 +128,24 @@ export class ModalKit extends ModalBuilder {
123128 return this ;
124129 }
125130
131+ /**
132+ * Sets the handler to run when the interaction collector ends.
133+ * @param handler - The handler to run when the interaction collector ends.
134+ * @returns This instance of the modal builder.
135+ */
136+ public onError ( handler : EventInterceptorErrorHandler ) : this {
137+ if ( ! handler ) {
138+ throw new TypeError (
139+ 'Cannot setup "onError" without a handler function parameter.' ,
140+ ) ;
141+ }
142+
143+ this . #contextData ??= { } ;
144+ this . #contextData. onError = handler ;
145+
146+ return this ;
147+ }
148+
126149 /**
127150 * Sets a filter for the interaction collector.
128151 * @param predicate - The filter to use for the interaction collector.
@@ -174,7 +197,7 @@ export class ModalKit extends ModalBuilder {
174197
175198 if ( ! handler ) return this . #unsub?.( ) ;
176199
177- return handler ( interaction ) ;
200+ return handler ( interaction , this ) ;
178201 } ,
179202 this . #contextData,
180203 ) ;
0 commit comments