@@ -12,6 +12,7 @@ import {
1212 ensureComponentUserAllowed ,
1313 mapSelectValues ,
1414 parseDiscordComponentData ,
15+ replyUnavailableComponentInteraction ,
1516 resolveAuthorizedComponentInteraction ,
1617 resolveInteractionCustomId ,
1718} from "./agent-components-helpers.js" ;
@@ -35,14 +36,10 @@ async function handleDiscordComponentEvent(params: {
3536 ) ;
3637 if ( ! parsed ) {
3738 logError ( `${ params . label } : failed to parse component data` ) ;
38- try {
39- await params . interaction . reply ( {
40- content : "This component is no longer valid." ,
41- ephemeral : true ,
42- } ) ;
43- } catch {
44- // Interaction may have expired
45- }
39+ await replyUnavailableComponentInteraction (
40+ params . interaction ,
41+ "This component is no longer valid." ,
42+ ) ;
4643 return ;
4744 }
4845
@@ -51,14 +48,7 @@ async function handleDiscordComponentEvent(params: {
5148 consume : false ,
5249 } ) ;
5350 if ( ! entry ) {
54- try {
55- await params . interaction . reply ( {
56- content : "This component has expired." ,
57- ephemeral : true ,
58- } ) ;
59- } catch {
60- // Interaction may have expired
61- }
51+ await replyUnavailableComponentInteraction ( params . interaction , "This component has expired." ) ;
6252 return ;
6353 }
6454
@@ -101,26 +91,15 @@ async function handleDiscordComponentEvent(params: {
10191 consume : ! entry . reusable ,
10292 } ) ;
10393 if ( ! consumed ) {
104- try {
105- await params . interaction . reply ( {
106- content : "This component has expired." ,
107- ephemeral : true ,
108- } ) ;
109- } catch {
110- // Interaction may have expired
111- }
94+ await replyUnavailableComponentInteraction ( params . interaction , "This component has expired." ) ;
11295 return ;
11396 }
11497
11598 if ( consumed . kind === "modal-trigger" ) {
116- try {
117- await params . interaction . reply ( {
118- content : "This form is no longer available." ,
119- ephemeral : true ,
120- } ) ;
121- } catch {
122- // Interaction may have expired
123- }
99+ await replyUnavailableComponentInteraction (
100+ params . interaction ,
101+ "This form is no longer available." ,
102+ ) ;
124103 return ;
125104 }
126105
@@ -203,42 +182,27 @@ async function handleDiscordModalTrigger(params: {
203182 ) ;
204183 if ( ! parsed ) {
205184 logError ( `${ params . label } : failed to parse modal trigger data` ) ;
206- try {
207- await params . interaction . reply ( {
208- content : "This button is no longer valid." ,
209- ephemeral : true ,
210- } ) ;
211- } catch {
212- // Interaction may have expired
213- }
185+ await replyUnavailableComponentInteraction (
186+ params . interaction ,
187+ "This button is no longer valid." ,
188+ ) ;
214189 return ;
215190 }
216191 const entry = await resolveDiscordComponentEntryWithPersistence ( {
217192 id : parsed . componentId ,
218193 consume : false ,
219194 } ) ;
220195 if ( ! entry || entry . kind !== "modal-trigger" ) {
221- try {
222- await params . interaction . reply ( {
223- content : "This button has expired." ,
224- ephemeral : true ,
225- } ) ;
226- } catch {
227- // Interaction may have expired
228- }
196+ await replyUnavailableComponentInteraction ( params . interaction , "This button has expired." ) ;
229197 return ;
230198 }
231199
232200 const modalId = entry . modalId ?? parsed . modalId ;
233201 if ( ! modalId ) {
234- try {
235- await params . interaction . reply ( {
236- content : "This form is no longer available." ,
237- ephemeral : true ,
238- } ) ;
239- } catch {
240- // Interaction may have expired
241- }
202+ await replyUnavailableComponentInteraction (
203+ params . interaction ,
204+ "This form is no longer available." ,
205+ ) ;
242206 return ;
243207 }
244208
@@ -274,14 +238,7 @@ async function handleDiscordModalTrigger(params: {
274238 consume : ! entry . reusable ,
275239 } ) ;
276240 if ( ! consumed ) {
277- try {
278- await params . interaction . reply ( {
279- content : "This form has expired." ,
280- ephemeral : true ,
281- } ) ;
282- } catch {
283- // Interaction may have expired
284- }
241+ await replyUnavailableComponentInteraction ( params . interaction , "This form has expired." ) ;
285242 return ;
286243 }
287244
@@ -291,14 +248,7 @@ async function handleDiscordModalTrigger(params: {
291248 consume : false ,
292249 } ) ;
293250 if ( ! modalEntry ) {
294- try {
295- await params . interaction . reply ( {
296- content : "This form has expired." ,
297- ephemeral : true ,
298- } ) ;
299- } catch {
300- // Interaction may have expired
301- }
251+ await replyUnavailableComponentInteraction ( params . interaction , "This form has expired." ) ;
302252 return ;
303253 }
304254
0 commit comments