Shard Connections

I am using Discordjs v14.9.0 Since 2 days, randomly my bot gets disconnected from Discord API, after x numbers of hours. I found nothing in debug logs or shard log. I don't know, how to counter this problem. Though, I was thinking, if we could use "Shard" Class to manually check its connection API after each Interval and if found closed, we just respawn it via "respawn()". I don't know, how to check the connection with API. Can anyone guide me through this?
23 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Elitex | Not well
- Node Version: v18.13.0 - What I have made till now:
manager.on('shardCreate', shard => {
console.log(`[SHARD MANAGER]: Launched shard #${shard.id}`);
const func = async () => {
await shard.respawn({timeout: -1});
};

shard.on('death', func);
shard.on('disconnect', func);

shard.on('ready', () => {
setInterval(async () => {
await shard.eval(client => client.users.fetch("767383867031945236", {force: true}))
.catch(e => shard.respawn({timeout: -1}));
}, 30_000);
});

});
manager.on('shardCreate', shard => {
console.log(`[SHARD MANAGER]: Launched shard #${shard.id}`);
const func = async () => {
await shard.respawn({timeout: -1});
};

shard.on('death', func);
shard.on('disconnect', func);

shard.on('ready', () => {
setInterval(async () => {
await shard.eval(client => client.users.fetch("767383867031945236", {force: true}))
.catch(e => shard.respawn({timeout: -1}));
}, 30_000);
});

});
Mac
Mac2y ago
Unsure if this can help out but why not use the shardError event to have some additional debugging?
Elitex | Not well
I have that Event as well
Mac
Mac2y ago
What's the code you used for that? it's not in the snippet you sent.
Elitex | Not well
umm, my snippet is regarding, What I want to make 2nd para in my post message.
Mac
Mac2y ago
yes but what code do you have for "shardError" I don't see anything in your paragraph
Elitex | Not well
just log um you mean, shard.on("error", func) ?
Mac
Mac2y ago
because on all your errors, you just try to respawn the shard without logging anything https://old.discordjs.dev/#/docs/discord.js/14.11.0/class/Client?scrollTo=e-shardError
Elitex | Not well
I don't see it here
Elitex | Not well
in Shard class ^ docs*
Mac
Mac2y ago
The one I sent is apart of all the other events
Elitex | Not well
yea, I have this one for logging in sep file
Mac
Mac2y ago
and nothing logs either?
Elitex | Not well
yep nothing
Mac
Mac2y ago
odd. yeah probably best to wait for someone with more experience than me on this one
Elitex | Not well
hm its way odd, I am using the package at v14.9 since it's released. Since 2 days, it started doing that shrug
Mac
Mac2y ago
update your package and try
Elitex | Not well
I don't wanna hit downtime, cz of connection issues in new version as said in announcement
Mac
Mac2y ago
How many servers is your bot in? and im unsure about having any downtime with the latest version - 14.11.0
Elitex | Not well
2100+ lemii see upgrading the stuff - https://github.com/discordjs/discord.js/issues/9139#issuecomment-1537589759 Though, I was thinking, if we could use "Shard" Class to manually check its connection API after each Interval and if found closed, we just respawn it via "respawn()". I don't know, how to check the connection with API. What about this ??
dzlandis
dzlandis2y ago
I also think I am having a similar problem Upgrading to v14.11 did not fix the issue for me, assuming that this problem is the same as mine I've been talking about my problem in #Bot Shards Keep Reconnecting After Reboot. I just made a comment on that github issue you referenced.
Elitex | Not well
ohk I have updated to v14.11, less see how it goes Issue resolved with updating Djs to v14.11.0

Did you find this page helpful?