Trying to detect if a shard goes offline

I am trying to make it so on shardcreate it gets the client.ws.ping or client.ws.status. The issue is that when I disconnect my wifi it still returns 0 for the status (same as when its on and connected), and the ping remains frozen at the last value (Not switching to -1 like I would expect) Here Is the code(I am using express to send a thing based on if its running or not): Also again client.ws.status cant be compared to WebSocket.OPEN since its always 0
manager.on("shardCreate", (shard: Shard) => {
console.log(`Shard ${shard.id} launched`);

shard.once("ready", async () => {
app.get(`/ping${shard.id}`, async (req, res) => {
// if ((await shard.eval(`this.ws.status`)) == WebSocket.OPEN)
res.status(200).send(`Ok ${(await shard.eval(`this.ws.status`))}`).end();
});
});
});
manager.on("shardCreate", (shard: Shard) => {
console.log(`Shard ${shard.id} launched`);

shard.once("ready", async () => {
app.get(`/ping${shard.id}`, async (req, res) => {
// if ((await shard.eval(`this.ws.status`)) == WebSocket.OPEN)
res.status(200).send(`Ok ${(await shard.eval(`this.ws.status`))}`).end();
});
});
});
This whole setup is so that I can monitor the bot by pinging it eventually but I cant detect if its on like this, how would I do this?
1 Reply
d.js toolkit
d.js toolkit16mo ago
- 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!
Want results from more Discord servers?
Add your server