Skip to content

Commit 73a1cd3

Browse files
committed
Fix async list and remove
1 parent cefe50f commit 73a1cd3

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/index.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,18 +1734,46 @@ async function handleRemoveWithSubdomains(interaction: DiscordInteraction, env:
17341734
};
17351735
}
17361736

1737-
// Send deferred response (shows "Bot is thinking...")
1738-
const deferredResponse = {
1737+
// Defer the response since this might take time with many subdomains
1738+
const deferResponse = {
17391739
type: 5, // DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
17401740
data: {}
17411741
};
17421742

1743-
// Start the async removal process (fire and forget)
1744-
performRemoveWithSubdomainsAsync(interaction, env, domain).catch(error => {
1745-
console.error("Async removal failed:", error);
1746-
});
1747-
1748-
return deferredResponse;
1743+
try {
1744+
// Do the actual work and send followup BEFORE returning
1745+
await performRemoveWithSubdomainsAsync(interaction, env, domain);
1746+
return deferResponse;
1747+
1748+
} catch (error) {
1749+
console.error("Error removing domains:", error);
1750+
1751+
// Try to send error as followup
1752+
const followupUrl = `https://discord.com/api/v10/webhooks/${interaction.application_id}/${interaction.token}`;
1753+
1754+
try {
1755+
await fetch(followupUrl, {
1756+
method: 'POST',
1757+
headers: {
1758+
'Content-Type': 'application/json'
1759+
},
1760+
body: JSON.stringify({
1761+
content: `❌ Failed to remove domains: ${error instanceof Error ? error.message : String(error)}`
1762+
})
1763+
});
1764+
1765+
return deferResponse;
1766+
} catch (followupError) {
1767+
console.error("Failed to send followup error:", followupError);
1768+
return {
1769+
type: 4,
1770+
data: {
1771+
content: `❌ Failed to remove domains: ${error instanceof Error ? error.message : String(error)}`,
1772+
flags: 64
1773+
}
1774+
};
1775+
}
1776+
}
17491777
}
17501778

17511779
async function performListDomainsAsync(interaction: DiscordInteraction, env: Env): Promise<void> {

0 commit comments

Comments
 (0)