Handling DiscordJS API Errors
Hello everyone, I've been trying to handle API response errors to avoid my Bot to die once these occur, errors like character limit exceeded or too many options on a command, the problem is: I am not sure where can I capture these errors because using the function catch() only works on certain cases, for example on the put request only works when i have 25 options (the limit) if i have 26 it will not be captured by the catch and just kill the bot.
7 Replies
• 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.For reference, this happens (image) when a command or subcommand have exactly 25 options, the bot don't die and I can capture and handle the error with the .cath() function, but when I have 26 or more options the Bot die.
make a global catch, and use a process manager like pm2 to automatically restart your bot
the thing is, I want to capture the error and display it on console, and as I am loading the commands configuration from a firebase collection restarting it will made it fail again, so I need to capture the error to handle it properly.
and in this way never enters the catch
i'm not sure what you mean. If you get an error, it indeed will fail again if you restert without fixing the error
but to make a global catch, make something like
Thanks, yes! what I wanted to do is load the last working command configuration when it fails to load the current one, but my issue was my bot was dying without capturing the error so that solution was not executing.
but It seems this is working so far, thank you.