[14.14.1] Check if awaitMessageComponent hit timeout or some other code failed

Would it be possible to detect whether awaitMessageComponent failed because of the timeout, or some other error occurred in the code? For example:
try {
const res = await interaction.editReply({ embeds: [embed], components: [row], files: [file] });
const confirmation = await res.awaitMessageComponent<ComponentType.Button>({ filter: (i) => i.user.id === userID, time: 60000 });
throw new Error('test');
} catch (e) {
if (e instanceof ...) {
console.log('No response after 60 seconds');
} else {
console.log(e);
}
}
try {
const res = await interaction.editReply({ embeds: [embed], components: [row], files: [file] });
const confirmation = await res.awaitMessageComponent<ComponentType.Button>({ filter: (i) => i.user.id === userID, time: 60000 });
throw new Error('test');
} catch (e) {
if (e instanceof ...) {
console.log('No response after 60 seconds');
} else {
console.log(e);
}
}
I'm not sure how to detect/where to get the error class from tho. I already tried: DiscordjsErrorCodes.InteractionCollectorError (as it's rejected with new DiscordjsError(ErrorCodes.InteractionCollectorError, reason)), however, I got the following error: "The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method." I guess this is this case since ErrorCodes.InteractionCollectorError isn't a class, but rather just an error code? Not sure about this tho. Thanks in advance
5 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
mallusrgreat
mallusrgreat9mo ago
just put the awaitMessageComponent in its own try-catch, it will only go to the catch block when no components are received
psyche
psycheOP9mo ago
Yes fair enough, but I'm wondering if it would somehow be possible to detect the error anyway
mallusrgreat
mallusrgreat9mo ago
the error will be DiscordjsError and error code will be ErrorCodes.InteractionCollectorError
psyche
psycheOP9mo ago
❤️ tysm
Want results from more Discord servers?
Add your server