Sending an error to the channel the error was caught on
I have a simple error handling script that checks for
uncaughtException
s, and if one pops up sends an error log both to the bot's console and to a dedicated error channel for internal use as an embed. If possible, I'd also like to send this embed to the user - for example, if a Slash Command fails, generate an error message and send it to the same channel the Slash Command was sent on.
Is it possible to somehow get the sent interaction (and with it, the channel) that caused the error? I know I could encase my commands in a try-catch loop, but if possible, I'd rather not do that for every command I have.
4 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.do you use an interaction command handler? you can use a try catch block there so you dont do it on all your commands, use async await, and basically if something fails it should be catched in the catch block where you have access to the interaction and the channel
This is largely why "simple" error handling like this isn't really the best approach. Catching individual errors at the source allows you to handle them properly
Yeah that makes sense! I use the premade WOKCommands library instead of an interaction handler built from scratch, so I might have to look into
catch
-ing using that. (If not creating my own command handler by myself, lol)
For sure! This was my naive approach just looking up how other people do it, but it's not super useful if I actually want to return the error š