From 98b7f840be40dc696be0b1159e328e657e580977 Mon Sep 17 00:00:00 2001
From: Luca Matei Pintilie <lucafulger@gmail.com>
Date: Tue, 16 Aug 2022 18:29:33 +0200
Subject: Delete the correct interaction

---
 src/srcom/slash_commands.tsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src/srcom/slash_commands.tsx')

diff --git a/src/srcom/slash_commands.tsx b/src/srcom/slash_commands.tsx
index 76b1280..7c6a710 100644
--- a/src/srcom/slash_commands.tsx
+++ b/src/srcom/slash_commands.tsx
@@ -339,6 +339,9 @@ async function sendCommand(
 ) {
 	const controller = new AbortController();
 	const cancelButtonId = crypto.randomUUID();
+
+	controller.signal.addEventListener("abort", () => i.deleteResponse());
+
 	runningTasks.set(cancelButtonId, { signal: controller, user: i.user.id });
 	const CancelButton = (
 		<>
@@ -391,7 +394,7 @@ async function sendCommand(
 			i.data.options.map((opt) => `${opt.name}:${opt.value}`)
 		}`;
 		if (err instanceof DOMException && err.name === "AbortError") {
-			await i.deleteResponse();
+			// Command canceled so just don't do anything
 		} else if (err instanceof CommandError) {
 			console.debug(err);
 			await i.editResponse(`Error: ${err.message}`);
@@ -460,7 +463,6 @@ export class SpeedrunCom extends ApplicationCommandsModule {
 				ephemeral: true,
 			});
 		}
-		await i.deleteResponse();
 		runningTasks.delete(i.customID);
 	}
 
-- 
cgit v1.2.3

