log bot out without errors
How can I log the bot out and then not have any errors when making requests. Like the bot still tried to send messages and it errors but how can I stop it from throwing an error then
5 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
try...catch
The try...catch statement is comprised of a try block and either a catch block, a finally block, or both. The code in the try block is executed first, and if it throws an exception, the code in the catch block will be executed. The code in the finally block will always be executed before control flow exits the entire construct.
I've used a try catch on my entire app and then also listened to error event to log it out and so many messages r still being sent that it runs out of memory and crashes
Even with a try catch
There is no world where you bot should be so erroneous that it causes your process to run out of memory
What is causing them? If it's something like missing permissions, you should check the permissions in a channel before attempting to even send the API request to send the message, for instance. There are still some scenarios where you must catch the error (e.g. DMing users), but there are many others where you can be proactive.
Yes there r set intervals but I'm not sure how to clear all them without exporting each individual one
After I log out the errors start to log from try catch and then js error that says it ran out of memory
So when i log the bot out I do that ?
Or clearInterval()
Oh I see but will clear interval stop it if it's in the middle of the call? And unref will wait till the call to stop? But when i call the method to log out the client how could I tell it to unref then because i don't want to exit the process because then hosting provider will restart it
When I make a commit my hosting provider starts a new process while keeping the old one so 2 bots r in at once. I use pub sub to communicate that there is a new server and then i need to log the bot out and basically exit the process without doing process.exit() otherwise the hosting provider thinks it crashed and will restart it
I explained more here https://discord.com/channels/222078108977594368/869652447881207858/1039903424008966164
So would I have to use clear interval or is there a way to just replace the entire process with another one
Yep exactly
Around 5+ minutes
Sometimes I'll make a commit, let's say 2 of them with 1 minute span in between then for 5+ mins there will be 3 bots logged in
No it's just the default state of how it works so I think the solution is by ending the process without actually using process.exit(). kinda like blocking it