#Gracefully stop the bot
14 messages · Page 1 of 1 (latest)
• 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.
I think you need to await the setPresence since destroying the client might stop your request from actually firing
setPresence does not return a Promise, it returns the presence synchronically, looking at the type definitions…
(discord.js/typings/index.d.ts)
I tried to await another API thing before destroying the client (force fetching the client user, to be exact), but the bot still didn't immediately switch to offline after stopping it
I uses the Ws, thats why it's sync
Maybe add an 1-2s cooldown before destroying? idk
Ws? As in websockets?
It calls the websocket to the change, not a rest request and when you destroy the client you also destroy the Ws
That might be the race condition
There's another weird thing: editing a message in the exit handler takes around 15 seconds…
let exitHandled = false;
async function exitHandler() {
try {
if (exitHandled) return;
exitHandled = true;
console.log("Handling exit…");
disableAllButtons = true;
console.debug("Refreshing volume message…");
await refresh();
console.debug("Setting offline presence…");
client.user!.setPresence({
status: "invisible"
});
await Utils.delay(1000);
console.debug("Destroying the client…");
await client.destroy();
console.log("Handled.");
} catch(e) {
console.error(e);
} finally {
process.exit(0);
}
}
```this is the handler