mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: Updated handling of interaction errors
This commit is contained in:
1 parent
8a0ade3ac4
commit
da919d1c5a
1 file changed
+27
-21
@@ -4,6 +4,7 @@ import {
|
|||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
Interaction,
|
Interaction,
|
||||||
InteractionReplyOptions,
|
InteractionReplyOptions,
|
||||||
|
InteractionType,
|
||||||
MessageComponentInteraction
|
MessageComponentInteraction
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { Logger } from 'pino';
|
import { Logger } from 'pino';
|
||||||
@@ -39,48 +40,53 @@ export const handleError = async (
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.error({ error, interaction }, `Error handling interaction '${interactionIdentifier}'`);
|
logger.debug(error, `Error handling interaction '${interactionIdentifier}' with execution ID ${executionId}`);
|
||||||
|
|
||||||
if (interaction instanceof ChatInputCommandInteraction && interaction.deferred) {
|
if (interaction instanceof ChatInputCommandInteraction) {
|
||||||
switch (interaction.replied) {
|
switch (interaction.replied) {
|
||||||
case true:
|
case true:
|
||||||
logger.warn(error, `Interaction '${interaction.id}' threw an error but has already been replied to.`);
|
logger.warn(
|
||||||
|
error,
|
||||||
|
`Interaction '${interactionIdentifier}' threw an error but has already been replied to.`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
case false:
|
case false:
|
||||||
logger.debug('Responding with error embed');
|
logger.debug('Responding with error embed');
|
||||||
return await interaction.editReply(errorReply);
|
return await interaction.editReply(errorReply);
|
||||||
}
|
}
|
||||||
} else if (interaction instanceof MessageComponentInteraction && interaction.deferred) {
|
} else if (interaction instanceof MessageComponentInteraction) {
|
||||||
switch (interaction.replied) {
|
switch (interaction.replied) {
|
||||||
case true:
|
case true:
|
||||||
logger.warn(error, `Interaction '${interaction.id}' threw an error but has already been replied to.`);
|
logger.warn(
|
||||||
|
error,
|
||||||
|
`Interaction '${interactionIdentifier}' threw an error but has already been replied to.`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
case false:
|
case false:
|
||||||
logger.debug('Responding with error embed');
|
logger.debug('Responding with error embed');
|
||||||
return await interaction.editReply(errorReply);
|
return await interaction.editReply(errorReply);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.debug(
|
||||||
'Interaction threw an error but was not deferred or replied to, or was an autocomplete interaction. Cannot send error reply.'
|
`${
|
||||||
|
InteractionType[interaction.type]
|
||||||
|
} interaction '${interactionIdentifier}' threw an error. Cannot send error reply.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
|
||||||
error.code === 'InteractionCollectorError' ||
|
|
||||||
error.message === 'Collector received no interactions before ending with reason: time'
|
|
||||||
) {
|
|
||||||
logger.debug('Interaction response timed out.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.message === 'Unknown interaction') {
|
if (error.message === 'Unknown interaction') {
|
||||||
logger.debug('Interaction has already been responded to or does no longer exist.');
|
logger.debug('Interaction no longer exists, timed out or has already been responded to.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.fatal(
|
if (error.message === 'Collector received no interactions before ending with reason: time') {
|
||||||
error,
|
logger.debug('Interaction collector response timed out.');
|
||||||
`Unhandled error while awaiting or handling component interaction. Execution ID: ${executionId}`
|
return;
|
||||||
);
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.fatal(
|
||||||
|
error,
|
||||||
|
`Unhandled error while handling interaction '${interactionIdentifier}'. Execution ID: ${executionId}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user