#Error handling within an interaction

15 messages · Page 1 of 1 (latest)

molten granite
#

Hi!

I have a slash command for my bot and given it is collecting a lot of data, I defer the reply at the start, how can I reply to the interaction if an error occurs saying the slash command failed?

peak thistle
#

• 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.

molten granite
shrewd kettle
#

Catch the error and then .editReply to update the deferred message to whatever feedback you want to give to users

wanton mesa
#

@molten granite use try and catch

molten granite
#

Should the code above work?

shrewd kettle
#

Should work but can allow uncaught promise rejections if editReply encounters errors

molten granite
#

this is the specific error I run into on occasion

#

how could I create an interaction reply if this error occurs?

shrewd kettle
#

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
molten granite
#

Would this work?

shrewd kettle
#

Seems fine. Try it