#Error handling within an interaction
15 messages · Page 1 of 1 (latest)
• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
npm list discord.js: [email protected]
node -v: v16.14.0
Catch the error and then .editReply to update the deferred message to whatever feedback you want to give to users
@molten granite use try and catch
console.error(error);
interaction.editReply({ content: 'An error occurred during the data collection process, please try again later!', components: [] });
});```
Should the code above work?
Should work but can allow uncaught promise rejections if editReply encounters errors
[cause]: AxiosError: Request failed with status code 400
this is the specific error I run into on occasion
how could I create an interaction reply if this error occurs?
I do:
- interaction.editReply({ content: 'An error occurred during the data collection process, please try again later!', components: [] });
+ return interaction.editReply({ content: 'An error occurred during the data collection process, please try again later!', components: [] });
``` so that any errors from the edit will be based to my handler
console.error(error);
return interaction.editReply({ content: 'An error occurred during the data collection process, please try again later!', components: [] });
});
Would this work?
Seems fine. Try it