How to handle HTTP errors?
https://discordjs.guide/popular-topics/errors
I've read this and still don't know how to properly handle HTTP errors.
I don't really know how to handle a
403 (FORBIDDEN)
error for example.
How can I do this?
Update: Can I just do this?
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
23 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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!Prob just let the program die because the token is no longer valid
Or ur talking abt forbidden
oh, my bad haha
Yeah, forbidden
and any additional errors
It depends on the context
Like for interactions, reply ephemerally that you are missing permissions
When I try to timeout or ban someone for example
The status text usually gives you more insight
Or the code in this case
Error.code is not the status code btw
aaand how to access the code?
well, is it a DiscordjsError if it's an API error?
We should have an enum for api error codes
.
is my approach at least correct?
discord-api-types documentation
discord-api-types - Imagine typings
discord-api-types is a simple Node/Deno module that brings up to date typings for Discord's API
🔍
Huh, must be a generic Unauthorized then
is my approach at least correct?
The second if should be inside the first one
what :kekw:
You can only guarantee error.code exists if error is a DiscordAPIError
Otherwise, error could be undefined or null for all you know
error?.code
or error instance of DiscordAPIError
?The second if statement belongs in the first one
I'm not sure if I get it but you mean this? (Example)
aaaaah
noice
-# I will mark this as solved as soon as it's working because I need to test it out tomorrow