@minesa-org/mini-interaction 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/MiniInteraction.js +9 -10
- package/dist/utils/CommandInteractionOptions.d.ts +4 -4
- package/dist/utils/CommandInteractionOptions.js +12 -6
- package/dist/utils/MessageComponentInteraction.d.ts +62 -24
- package/dist/utils/MessageComponentInteraction.js +11 -7
- package/dist/utils/ModalSubmitInteraction.d.ts +3 -3
- package/dist/utils/ModalSubmitInteraction.js +2 -2
- package/dist/utils/interactionMessageHelpers.js +7 -0
- package/package.json +1 -1
|
@@ -101,10 +101,6 @@ export class MiniInteraction {
|
|
|
101
101
|
this.trackInteractionState(interactionId, state.token, 'expired');
|
|
102
102
|
return false;
|
|
103
103
|
}
|
|
104
|
-
// Check if already responded
|
|
105
|
-
if (state.state === 'responded') {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
104
|
return true;
|
|
109
105
|
}
|
|
110
106
|
/**
|
|
@@ -1126,7 +1122,7 @@ export class MiniInteraction {
|
|
|
1126
1122
|
ackResolver = resolve;
|
|
1127
1123
|
});
|
|
1128
1124
|
// Helper to send follow-up responses via webhooks
|
|
1129
|
-
const sendFollowUp = (token, data) => this.sendFollowUp(token, data);
|
|
1125
|
+
const sendFollowUp = (token, data, messageId = '@original') => this.sendFollowUp(token, data, messageId);
|
|
1130
1126
|
const interactionWithHelpers = createMessageComponentInteraction(interaction, {
|
|
1131
1127
|
onAck: (response) => ackResolver?.(response),
|
|
1132
1128
|
sendFollowUp,
|
|
@@ -1191,7 +1187,7 @@ export class MiniInteraction {
|
|
|
1191
1187
|
ackResolver = resolve;
|
|
1192
1188
|
});
|
|
1193
1189
|
// Helper to send follow-up responses via webhooks
|
|
1194
|
-
const sendFollowUp = (token, data) => this.sendFollowUp(token, data);
|
|
1190
|
+
const sendFollowUp = (token, data, messageId = '@original') => this.sendFollowUp(token, data, messageId);
|
|
1195
1191
|
const interactionWithHelpers = createModalSubmitInteraction(interaction, {
|
|
1196
1192
|
onAck: (response) => ackResolver?.(response),
|
|
1197
1193
|
sendFollowUp,
|
|
@@ -1259,7 +1255,7 @@ export class MiniInteraction {
|
|
|
1259
1255
|
ackResolver = resolve;
|
|
1260
1256
|
});
|
|
1261
1257
|
// Helper to send follow-up responses via webhooks
|
|
1262
|
-
const sendFollowUp = (token, data) => this.sendFollowUp(token, data);
|
|
1258
|
+
const sendFollowUp = (token, data, messageId = '@original') => this.sendFollowUp(token, data, messageId);
|
|
1263
1259
|
// Create a timeout wrapper for the command handler
|
|
1264
1260
|
const timeoutWrapper = createTimeoutWrapper(async () => {
|
|
1265
1261
|
// Check if it's a chat input (slash) command
|
|
@@ -1351,15 +1347,18 @@ export class MiniInteraction {
|
|
|
1351
1347
|
* Sends a follow-up response or edits an existing response via Discord's interaction webhooks.
|
|
1352
1348
|
* This is used for interactions that have already been acknowledged (e.g., via deferReply).
|
|
1353
1349
|
*/
|
|
1354
|
-
async sendFollowUp(token, response) {
|
|
1355
|
-
const
|
|
1350
|
+
async sendFollowUp(token, response, messageId = "@original") {
|
|
1351
|
+
const isEdit = messageId !== "";
|
|
1352
|
+
const url = isEdit
|
|
1353
|
+
? `${DISCORD_BASE_URL}/webhooks/${this.applicationId}/${token}/messages/${messageId}`
|
|
1354
|
+
: `${DISCORD_BASE_URL}/webhooks/${this.applicationId}/${token}`;
|
|
1356
1355
|
// Only send follow-up if there is data to send
|
|
1357
1356
|
if (!('data' in response) || !response.data) {
|
|
1358
1357
|
return;
|
|
1359
1358
|
}
|
|
1360
1359
|
try {
|
|
1361
1360
|
const fetchResponse = await this.fetchImpl(url, {
|
|
1362
|
-
method: "PATCH",
|
|
1361
|
+
method: isEdit ? "PATCH" : "POST",
|
|
1363
1362
|
headers: {
|
|
1364
1363
|
"Content-Type": "application/json",
|
|
1365
1364
|
},
|
|
@@ -144,9 +144,9 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
|
|
|
144
144
|
options: CommandInteractionOptionResolver;
|
|
145
145
|
getResponse(): APIInteractionResponse | null;
|
|
146
146
|
reply(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource;
|
|
147
|
-
followUp(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource
|
|
147
|
+
followUp(data: InteractionMessageData): Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
148
148
|
edit(data?: InteractionMessageData): APIInteractionResponseUpdateMessage;
|
|
149
|
-
editReply(data?: InteractionMessageData): APIInteractionResponseUpdateMessage
|
|
149
|
+
editReply(data?: InteractionMessageData): Promise<APIInteractionResponseUpdateMessage>;
|
|
150
150
|
deferReply(options?: DeferReplyOptions): APIInteractionResponseDeferredChannelMessageWithSource;
|
|
151
151
|
showModal(data: APIModalInteractionResponseCallbackData | {
|
|
152
152
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
@@ -155,7 +155,7 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
|
|
|
155
155
|
canRespond?(interactionId: string): boolean;
|
|
156
156
|
trackResponse?(interactionId: string, token: string, state: 'responded' | 'deferred'): void;
|
|
157
157
|
onAck?(response: APIInteractionResponse): void;
|
|
158
|
-
sendFollowUp?(token: string, response: APIInteractionResponse): void
|
|
158
|
+
sendFollowUp?(token: string, response: APIInteractionResponse, messageId?: string): Promise<void>;
|
|
159
159
|
}
|
|
160
160
|
export declare const CommandInteraction: {};
|
|
161
161
|
/**
|
|
@@ -170,5 +170,5 @@ export declare function createCommandInteraction(interaction: APIChatInputApplic
|
|
|
170
170
|
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
171
171
|
logTiming?: (interactionId: string, operation: string, startTime: number, success: boolean) => void;
|
|
172
172
|
onAck?: (response: APIInteractionResponse) => void;
|
|
173
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void
|
|
173
|
+
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
174
174
|
}): CommandInteraction;
|
|
@@ -327,6 +327,8 @@ export const CommandInteraction = {};
|
|
|
327
327
|
export function createCommandInteraction(interaction, helpers) {
|
|
328
328
|
const options = new CommandInteractionOptionResolver(interaction.data.options, interaction.data.resolved);
|
|
329
329
|
let capturedResponse = null;
|
|
330
|
+
let isDeferred = false;
|
|
331
|
+
let hasResponded = false;
|
|
330
332
|
/**
|
|
331
333
|
* Stores the most recent response helper payload for later retrieval.
|
|
332
334
|
*/
|
|
@@ -382,32 +384,35 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
382
384
|
const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
383
385
|
// Track response
|
|
384
386
|
this.trackResponse?.(this.id, this.token, 'responded');
|
|
387
|
+
hasResponded = true;
|
|
385
388
|
// Notify acknowledgment
|
|
386
389
|
this.onAck?.(response);
|
|
387
390
|
return response;
|
|
388
391
|
},
|
|
389
|
-
followUp(data) {
|
|
392
|
+
async followUp(data) {
|
|
390
393
|
const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
391
394
|
if (this.sendFollowUp) {
|
|
392
|
-
|
|
395
|
+
// Empty string for messageId means a new follow-up (POST)
|
|
396
|
+
await this.sendFollowUp(this.token, response, '');
|
|
393
397
|
}
|
|
394
398
|
return response;
|
|
395
399
|
},
|
|
396
400
|
edit(data) {
|
|
397
401
|
return createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
398
402
|
},
|
|
399
|
-
editReply(data) {
|
|
403
|
+
async editReply(data) {
|
|
400
404
|
// Validate interaction can respond
|
|
401
405
|
if (!this.canRespond?.(this.id)) {
|
|
402
|
-
throw new Error('Interaction cannot edit reply:
|
|
406
|
+
throw new Error('Interaction cannot edit reply: expired');
|
|
403
407
|
}
|
|
404
408
|
const response = createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
405
409
|
// If it's already deferred or responded, we MUST use a webhook
|
|
406
|
-
if (this.sendFollowUp) {
|
|
407
|
-
this.sendFollowUp(this.token, response);
|
|
410
|
+
if (this.sendFollowUp && (isDeferred || hasResponded)) {
|
|
411
|
+
await this.sendFollowUp(this.token, response, '@original');
|
|
408
412
|
}
|
|
409
413
|
// Track response
|
|
410
414
|
this.trackResponse?.(this.id, this.token, 'responded');
|
|
415
|
+
hasResponded = true;
|
|
411
416
|
return response;
|
|
412
417
|
},
|
|
413
418
|
deferReply(options) {
|
|
@@ -420,6 +425,7 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
420
425
|
: undefined);
|
|
421
426
|
// Track deferred state
|
|
422
427
|
this.trackResponse?.(this.id, this.token, 'deferred');
|
|
428
|
+
isDeferred = true;
|
|
423
429
|
// Notify acknowledgment
|
|
424
430
|
this.onAck?.(response);
|
|
425
431
|
return response;
|
|
@@ -18,69 +18,110 @@ export declare const ResolvedMentionableOption: {};
|
|
|
18
18
|
/**
|
|
19
19
|
* Base helper methods available on all component interactions.
|
|
20
20
|
*/
|
|
21
|
-
type BaseComponentInteractionHelpers = {
|
|
22
|
-
|
|
23
|
-
reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource;
|
|
24
|
-
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
25
|
-
update: (data?: InteractionMessageData) => APIInteractionResponseUpdateMessage;
|
|
26
|
-
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
27
|
-
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
28
|
-
toJSON(): APIModalInteractionResponseCallbackData;
|
|
29
|
-
}) => APIModalInteractionResponse;
|
|
21
|
+
export type BaseComponentInteractionHelpers = {
|
|
22
|
+
trackTiming?: (interactionId: string, operation: string, startTime: number, success: boolean) => void;
|
|
30
23
|
onAck?: (response: APIInteractionResponse) => void;
|
|
31
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void
|
|
24
|
+
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
32
25
|
};
|
|
33
26
|
/**
|
|
34
27
|
* Button interaction with helper methods.
|
|
35
28
|
* Buttons don't have values or resolved data.
|
|
36
29
|
*/
|
|
37
|
-
export interface ButtonInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
30
|
+
export interface ButtonInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
38
31
|
data: APIMessageButtonInteractionData;
|
|
32
|
+
getResponse: () => APIInteractionResponse | null;
|
|
33
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
34
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
35
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
36
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
37
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
38
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
39
|
+
}) => APIModalInteractionResponse;
|
|
39
40
|
}
|
|
40
41
|
export declare const ButtonInteraction: {};
|
|
41
42
|
/**
|
|
42
43
|
* String select menu interaction with helper methods.
|
|
43
44
|
*/
|
|
44
|
-
export interface StringSelectInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
45
|
+
export interface StringSelectInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
45
46
|
data: APIMessageStringSelectInteractionData;
|
|
46
47
|
values: string[];
|
|
47
48
|
getStringValues: () => string[];
|
|
49
|
+
getResponse: () => APIInteractionResponse | null;
|
|
50
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
51
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
52
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
53
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
54
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
55
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
56
|
+
}) => APIModalInteractionResponse;
|
|
48
57
|
}
|
|
49
58
|
export declare const StringSelectInteraction: {};
|
|
50
59
|
/**
|
|
51
60
|
* Role select menu interaction with helper methods.
|
|
52
61
|
*/
|
|
53
|
-
export interface RoleSelectInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
62
|
+
export interface RoleSelectInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
54
63
|
data: APIMessageRoleSelectInteractionData;
|
|
55
64
|
values: string[];
|
|
56
65
|
getRoles: () => APIRole[];
|
|
66
|
+
getResponse: () => APIInteractionResponse | null;
|
|
67
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
68
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
69
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
70
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
71
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
72
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
73
|
+
}) => APIModalInteractionResponse;
|
|
57
74
|
}
|
|
58
75
|
export declare const RoleSelectInteraction: {};
|
|
59
76
|
/**
|
|
60
77
|
* User select menu interaction with helper methods.
|
|
61
78
|
*/
|
|
62
|
-
export interface UserSelectInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
79
|
+
export interface UserSelectInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
63
80
|
data: APIMessageUserSelectInteractionData;
|
|
64
81
|
values: string[];
|
|
65
82
|
getUsers: () => ResolvedUserOption[];
|
|
83
|
+
getResponse: () => APIInteractionResponse | null;
|
|
84
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
85
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
86
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
87
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
88
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
89
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
90
|
+
}) => APIModalInteractionResponse;
|
|
66
91
|
}
|
|
67
92
|
export declare const UserSelectInteraction: {};
|
|
68
93
|
/**
|
|
69
94
|
* Channel select menu interaction with helper methods.
|
|
70
95
|
*/
|
|
71
|
-
export interface ChannelSelectInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
96
|
+
export interface ChannelSelectInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
72
97
|
data: APIMessageChannelSelectInteractionData;
|
|
73
98
|
values: string[];
|
|
74
99
|
getChannels: () => APIInteractionDataResolvedChannel[];
|
|
100
|
+
getResponse: () => APIInteractionResponse | null;
|
|
101
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
102
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
103
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
104
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
105
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
106
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
107
|
+
}) => APIModalInteractionResponse;
|
|
75
108
|
}
|
|
76
109
|
export declare const ChannelSelectInteraction: {};
|
|
77
110
|
/**
|
|
78
111
|
* Mentionable select menu interaction with helper methods.
|
|
79
112
|
*/
|
|
80
|
-
export interface MentionableSelectInteraction extends Omit<APIMessageComponentInteraction, "data"
|
|
113
|
+
export interface MentionableSelectInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
81
114
|
data: APIMessageMentionableSelectInteractionData;
|
|
82
115
|
values: string[];
|
|
83
116
|
getMentionables: () => ResolvedMentionableOption[];
|
|
117
|
+
getResponse: () => APIInteractionResponse | null;
|
|
118
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
119
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
120
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
121
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
122
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
123
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
124
|
+
}) => APIModalInteractionResponse;
|
|
84
125
|
}
|
|
85
126
|
export declare const MentionableSelectInteraction: {};
|
|
86
127
|
/**
|
|
@@ -91,9 +132,9 @@ export declare const MentionableSelectInteraction: {};
|
|
|
91
132
|
*/
|
|
92
133
|
export type MessageComponentInteraction = APIMessageComponentInteraction & {
|
|
93
134
|
getResponse: () => APIInteractionResponse | null;
|
|
94
|
-
reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource
|
|
135
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
95
136
|
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
96
|
-
update: (data?: InteractionMessageData) => APIInteractionResponseUpdateMessage
|
|
137
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
97
138
|
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
98
139
|
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
99
140
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
@@ -102,7 +143,7 @@ export type MessageComponentInteraction = APIMessageComponentInteraction & {
|
|
|
102
143
|
* Finalise the interaction response via a webhook follow-up.
|
|
103
144
|
* This is automatically called by reply() and update() if the interaction is deferred.
|
|
104
145
|
*/
|
|
105
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void
|
|
146
|
+
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
106
147
|
/**
|
|
107
148
|
* The selected values from a select menu interaction.
|
|
108
149
|
* This property is only present for select menu interactions.
|
|
@@ -140,10 +181,7 @@ export declare const MessageComponentInteraction: {};
|
|
|
140
181
|
* Wraps a raw component interaction with helper methods mirroring Discord's expected responses.
|
|
141
182
|
*
|
|
142
183
|
* @param interaction - The raw interaction payload from Discord.
|
|
184
|
+
* @param helpers - Optional callback to capture the final interaction response.
|
|
143
185
|
* @returns A helper-augmented interaction object.
|
|
144
186
|
*/
|
|
145
|
-
export declare function createMessageComponentInteraction(interaction: APIMessageComponentInteraction, helpers?:
|
|
146
|
-
onAck?: (response: APIInteractionResponse) => void;
|
|
147
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void;
|
|
148
|
-
}): MessageComponentInteraction;
|
|
149
|
-
export {};
|
|
187
|
+
export declare function createMessageComponentInteraction(interaction: APIMessageComponentInteraction, helpers?: BaseComponentInteractionHelpers): MessageComponentInteraction;
|
|
@@ -13,6 +13,7 @@ export const MessageComponentInteraction = {};
|
|
|
13
13
|
* Wraps a raw component interaction with helper methods mirroring Discord's expected responses.
|
|
14
14
|
*
|
|
15
15
|
* @param interaction - The raw interaction payload from Discord.
|
|
16
|
+
* @param helpers - Optional callback to capture the final interaction response.
|
|
16
17
|
* @returns A helper-augmented interaction object.
|
|
17
18
|
*/
|
|
18
19
|
export function createMessageComponentInteraction(interaction, helpers) {
|
|
@@ -22,7 +23,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
22
23
|
capturedResponse = response;
|
|
23
24
|
return response;
|
|
24
25
|
};
|
|
25
|
-
const reply = (data) => {
|
|
26
|
+
const reply = async (data) => {
|
|
26
27
|
const normalisedData = normaliseInteractionMessageData(data);
|
|
27
28
|
if (!normalisedData) {
|
|
28
29
|
throw new Error("[MiniInteraction] Component replies require response data to be provided.");
|
|
@@ -32,7 +33,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
32
33
|
data: normalisedData,
|
|
33
34
|
});
|
|
34
35
|
if (isDeferred && helpers?.sendFollowUp) {
|
|
35
|
-
helpers.sendFollowUp(interaction.token, response);
|
|
36
|
+
await helpers.sendFollowUp(interaction.token, response, '');
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
helpers?.onAck?.(response);
|
|
@@ -54,20 +55,23 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
54
55
|
helpers?.onAck?.(response);
|
|
55
56
|
return response;
|
|
56
57
|
};
|
|
57
|
-
const update = (data) => {
|
|
58
|
+
const update = async (data) => {
|
|
58
59
|
const normalisedData = normaliseInteractionMessageData(data);
|
|
59
|
-
const response = normalisedData
|
|
60
|
+
const response = captureResponse(normalisedData
|
|
60
61
|
? {
|
|
61
62
|
type: InteractionResponseType.UpdateMessage,
|
|
62
63
|
data: normalisedData,
|
|
63
64
|
}
|
|
64
65
|
: {
|
|
65
66
|
type: InteractionResponseType.UpdateMessage,
|
|
66
|
-
};
|
|
67
|
+
});
|
|
67
68
|
if (isDeferred && helpers?.sendFollowUp) {
|
|
68
|
-
helpers.sendFollowUp(interaction.token, response);
|
|
69
|
+
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
else {
|
|
72
|
+
helpers?.onAck?.(response);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
71
75
|
};
|
|
72
76
|
const deferUpdate = () => {
|
|
73
77
|
const response = captureResponse({
|
|
@@ -5,7 +5,7 @@ import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageH
|
|
|
5
5
|
*/
|
|
6
6
|
export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
7
7
|
getResponse: () => APIInteractionResponse | null;
|
|
8
|
-
reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource
|
|
8
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
9
9
|
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
10
10
|
/**
|
|
11
11
|
* Helper method to get the value of a text input component by its custom ID.
|
|
@@ -15,7 +15,7 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
|
15
15
|
* Finalise the interaction response via a webhook follow-up.
|
|
16
16
|
* This is automatically called by reply() if the interaction is deferred.
|
|
17
17
|
*/
|
|
18
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void
|
|
18
|
+
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
19
19
|
};
|
|
20
20
|
export declare const ModalSubmitInteraction: {};
|
|
21
21
|
/**
|
|
@@ -27,5 +27,5 @@ export declare const ModalSubmitInteraction: {};
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function createModalSubmitInteraction(interaction: APIModalSubmitInteraction, helpers?: {
|
|
29
29
|
onAck?: (response: APIInteractionResponse) => void;
|
|
30
|
-
sendFollowUp?: (token: string, response: APIInteractionResponse) => void
|
|
30
|
+
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
31
31
|
}): ModalSubmitInteraction;
|
|
@@ -15,7 +15,7 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
15
15
|
capturedResponse = response;
|
|
16
16
|
return response;
|
|
17
17
|
};
|
|
18
|
-
const reply = (data) => {
|
|
18
|
+
const reply = async (data) => {
|
|
19
19
|
const normalisedData = normaliseInteractionMessageData(data);
|
|
20
20
|
if (!normalisedData) {
|
|
21
21
|
throw new Error("[MiniInteraction] Modal replies require response data to be provided.");
|
|
@@ -25,7 +25,7 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
25
25
|
data: normalisedData,
|
|
26
26
|
});
|
|
27
27
|
if (isDeferred && helpers?.sendFollowUp) {
|
|
28
|
-
helpers.sendFollowUp(interaction.token, response);
|
|
28
|
+
await helpers.sendFollowUp(interaction.token, response, '');
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
helpers?.onAck?.(response);
|
|
@@ -52,6 +52,13 @@ export function normaliseInteractionMessageData(data) {
|
|
|
52
52
|
if (data.flags !== undefined) {
|
|
53
53
|
responseData.flags = normaliseMessageFlags(data.flags);
|
|
54
54
|
}
|
|
55
|
+
// Automatically handle IsComponentsV2 flag if Components V2 are detected
|
|
56
|
+
if (responseData.components && Array.isArray(responseData.components)) {
|
|
57
|
+
if (containsComponentsV2(responseData.components)) {
|
|
58
|
+
const currentFlags = responseData.flags ?? 0;
|
|
59
|
+
responseData.flags = (currentFlags | (0x1 << 12)); // 0x1 << 12 is IsComponentsV2
|
|
60
|
+
}
|
|
61
|
+
}
|
|
55
62
|
return responseData;
|
|
56
63
|
}
|
|
57
64
|
function containsComponentsV2(components) {
|
package/package.json
CHANGED