@minesa-org/mini-interaction 0.2.18 → 0.2.19
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.
|
@@ -397,6 +397,8 @@ export declare class MiniInteraction {
|
|
|
397
397
|
/**
|
|
398
398
|
* Sends a follow-up response or edits an existing response via Discord's interaction webhooks.
|
|
399
399
|
* This is used for interactions that have already been acknowledged (e.g., via deferReply).
|
|
400
|
+
*
|
|
401
|
+
* Includes retry logic to handle race conditions where the ACK hasn't reached Discord yet.
|
|
400
402
|
*/
|
|
401
403
|
private sendFollowUp;
|
|
402
404
|
}
|
|
@@ -1366,14 +1366,18 @@ export class MiniInteraction {
|
|
|
1366
1366
|
/**
|
|
1367
1367
|
* Sends a follow-up response or edits an existing response via Discord's interaction webhooks.
|
|
1368
1368
|
* This is used for interactions that have already been acknowledged (e.g., via deferReply).
|
|
1369
|
+
*
|
|
1370
|
+
* Includes retry logic to handle race conditions where the ACK hasn't reached Discord yet.
|
|
1369
1371
|
*/
|
|
1370
|
-
async sendFollowUp(token, response, messageId = "@original") {
|
|
1372
|
+
async sendFollowUp(token, response, messageId = "@original", retryCount = 0) {
|
|
1373
|
+
const MAX_RETRIES = 3;
|
|
1374
|
+
const BASE_DELAY_MS = 250; // Start with 250ms delay
|
|
1371
1375
|
const isEdit = messageId !== "";
|
|
1372
1376
|
const url = isEdit
|
|
1373
1377
|
? `${DISCORD_BASE_URL}/webhooks/${this.applicationId}/${token}/messages/${messageId}`
|
|
1374
1378
|
: `${DISCORD_BASE_URL}/webhooks/${this.applicationId}/${token}`;
|
|
1375
1379
|
if (this.timeoutConfig.enableResponseDebugLogging) {
|
|
1376
|
-
console.log(`[MiniInteraction] sendFollowUp: id=${messageId || 'new'}, edit=${isEdit}, url=${url}`);
|
|
1380
|
+
console.log(`[MiniInteraction] sendFollowUp: id=${messageId || 'new'}, edit=${isEdit}, retry=${retryCount}, url=${url}`);
|
|
1377
1381
|
}
|
|
1378
1382
|
// Only send follow-up if there is data to send
|
|
1379
1383
|
if (!('data' in response) || !response.data) {
|
|
@@ -1395,6 +1399,13 @@ export class MiniInteraction {
|
|
|
1395
1399
|
}
|
|
1396
1400
|
if (!fetchResponse.ok) {
|
|
1397
1401
|
const errorBody = await fetchResponse.text();
|
|
1402
|
+
// Check for "Unknown Webhook" error (10015) - this means ACK hasn't reached Discord yet
|
|
1403
|
+
if (fetchResponse.status === 404 && errorBody.includes("10015") && retryCount < MAX_RETRIES) {
|
|
1404
|
+
const delayMs = BASE_DELAY_MS * Math.pow(2, retryCount); // Exponential backoff: 250, 500, 1000ms
|
|
1405
|
+
console.warn(`[MiniInteraction] Webhook not ready yet, retrying in ${delayMs}ms (attempt ${retryCount + 1}/${MAX_RETRIES})`);
|
|
1406
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
1407
|
+
return this.sendFollowUp(token, response, messageId, retryCount + 1);
|
|
1408
|
+
}
|
|
1398
1409
|
console.error(`[MiniInteraction] Failed to send follow-up response (id=${messageId || 'new'}): [${fetchResponse.status}] ${errorBody}`);
|
|
1399
1410
|
if (fetchResponse.status === 404) {
|
|
1400
1411
|
console.error("[MiniInteraction] Hint: Interaction token might have expired or the message was deleted.");
|
package/package.json
CHANGED