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

6 messages · Page 1 of 1 (latest)

tropic quail
#

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);
  }
}

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

chilly forgeBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
quartz radish
tropic quail
#

Yes fair enough, but I'm wondering if it would somehow be possible to detect the error anyway

quartz radish
#

the error will be DiscordjsError

#

and error code will be ErrorCodes.InteractionCollectorError