Update specs.ts

Update the footer of the embed with context when the buttons are disabled
This commit is contained in:
sharpy66 2023-08-03 16:40:26 -07:00 committed by GitHub
parent 14e756f29f
commit 985493edee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -62,15 +62,24 @@ function createEmbed(device: any, searchQuery: string, results: number, index: n
// End listener function to disable buttons after message collector times out
function addEndListener(collector, previous, next, row, sentMessage) {
let endListenerAdded = false
let endListenerAdded = false;
// Function to be called when the collector ends to disable buttons and update message.
const endListener = async () => {
previous.setDisabled(true);
next.setDisabled(true);
await sentMessage.edit({ components: [row] }).catch(logger.error);
await sentMessage.edit({ components: [row] }).catch(console.error);
// Update footer text on timeout
const newEmbed = new EmbedBuilder(sentMessage.embeds[0])
.setFooter({ text: "Interaction timeout: Buttons disabled." });
await sentMessage.edit({ embeds: [newEmbed] });
collector.stop();
};
if (!endListenerAdded) {
// Add the end listener only if it hasn't already been added.
if (!endListenerAdded) {
collector.on('end', endListener);
endListenerAdded = true;
}