feat: Improve error handling in promptKeySelection for interaction updates and timeouts
This commit is contained in:
@@ -367,6 +367,7 @@ export async function promptKeySelection<T>(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await select.update({
|
await select.update({
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
@@ -381,8 +382,14 @@ export async function promptKeySelection<T>(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
collector.stop('selected');
|
} catch {
|
||||||
|
if (!select.deferred && !select.replied) {
|
||||||
|
try { await select.deferUpdate(); } catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finish(selected.entry, 'selected');
|
finish(selected.entry, 'selected');
|
||||||
|
collector.stop('selected');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +413,7 @@ export async function promptKeySelection<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.customId === `${config.customIdPrefix}_cancel` && interaction.isButton()) {
|
if (interaction.customId === `${config.customIdPrefix}_cancel` && interaction.isButton()) {
|
||||||
|
try {
|
||||||
await interaction.update({
|
await interaction.update({
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
@@ -417,8 +425,14 @@ export async function promptKeySelection<T>(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
collector.stop('cancelled');
|
} catch {
|
||||||
|
if (!interaction.deferred && !interaction.replied) {
|
||||||
|
try { await interaction.deferUpdate(); } catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finish(null, 'cancelled');
|
finish(null, 'cancelled');
|
||||||
|
collector.stop('cancelled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +488,7 @@ export async function promptKeySelection<T>(
|
|||||||
collector.on('end', async (_collected, reason) => {
|
collector.on('end', async (_collected, reason) => {
|
||||||
if (resolved) return;
|
if (resolved) return;
|
||||||
resolved = true;
|
resolved = true;
|
||||||
|
if (reason !== 'selected' && reason !== 'cancelled') {
|
||||||
const expiredPanel = {
|
const expiredPanel = {
|
||||||
type: 17,
|
type: 17,
|
||||||
accent_color: 0xFFA500,
|
accent_color: 0xFFA500,
|
||||||
@@ -484,7 +499,13 @@ export async function promptKeySelection<T>(
|
|||||||
try {
|
try {
|
||||||
await panelMessage.edit({ components: [expiredPanel] });
|
await panelMessage.edit({ components: [expiredPanel] });
|
||||||
} catch {}
|
} catch {}
|
||||||
const mappedReason: 'selected' | 'cancelled' | 'timeout' = reason === 'cancelled' ? 'cancelled' : 'timeout';
|
}
|
||||||
|
|
||||||
|
let mappedReason: 'selected' | 'cancelled' | 'timeout';
|
||||||
|
if (reason === 'selected') mappedReason = 'selected';
|
||||||
|
else if (reason === 'cancelled') mappedReason = 'cancelled';
|
||||||
|
else mappedReason = 'timeout';
|
||||||
|
|
||||||
resolve({ entry: null, panelMessage, reason: mappedReason });
|
resolve({ entry: null, panelMessage, reason: mappedReason });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user