Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord bot randomly appearing offline in guilds #9928

Open
qtAmyVT opened this issue Nov 6, 2023 · 7 comments
Open

Discord bot randomly appearing offline in guilds #9928

qtAmyVT opened this issue Nov 6, 2023 · 7 comments

Comments

@qtAmyVT
Copy link

qtAmyVT commented Nov 6, 2023

Which package is this bug report for?

discord.js

Issue description

I have a problem with the LTS version of discord.js v13. I own a bot which is on 6.5K guilds and lately started to appear offline after hours? or even days of running. The bot is mostly offline on Shard 3 and 5.

Meanwhile, the only fix for this problem is to restart the bot entirely. Interestingly enough, both shard events or discord.js debugging has not reporting any problem indicating with the network of the production server, the console doesn't give any valuable information for the trackdown of the source, no errors, no something strange. Nothing at all.

The code sample shows the shardmanager but the shard event logging are handled by the discord.js client itself seperate from the shardmanager.

Images are attached below:
librewolf_YyoS3l4Yhg
librewolf_OTn0My91w9
librewolf_GtzBxV6hyS

Code sample

const { ShardingManager } = require('discord.js');
let manager = new ShardingManager('./bot.js', {
    totalShards: 'auto',
    token: 'xxxxxxxxxxxx'
});

manager.on("debug", (e) => console.log(e));

manager.on("launch", (shard) => {
 console.log(`[WS => ${shard.id}] [✔] Successfully launched shard ${shard.id} of ${manager.totalShards}`);
 if(shard.id === 0) {
  console.log('[WS => catchUsers] [!] Refreshing modules before shard spawning...')
  console.log('[WS => catchUsers] [!] Lazy-reloading database before shard spawning...')
 }
});

manager.on("shardCreate", shard => {
    manager.on("ready", () => {
	console.log(`[${shard.id} => ready] [✔] Shard ${shard.id} (${shard.pid}) connected to Discord's Gateway.`)
        shard.send({ type: "shardId", data: { shardId: shard.id } });
    });
});

 manager.on("death", (process, shard) => {
  console.log("[${shard.id} => closeEvent] [⨯] Shard " + shard.id + " closed unexpectedly! PID: " + process.pid + "; Exit code: " + process.exitCode + ".");

  if(process.exitCode === null)
  {
   console.log("[${shard.id} => closeEvent] [!] Shard " + shard.id + " exited with NULL error code. This may be a result of a lack of available system memory. Ensure that there is enough memory allocated to continue.");
  }
 });

 manager.on("disconnect", (event) => {
  console.log("[${shard.id} => disconnect] [!] Shard " + shard.id + " disconnected. Dumping socket close event...");
  console.log(event);
 });
manager.spawn().catch(error => console.error(error));

Versions

  • discord.js 13.8.1
  • Node.js 18.18.2
  • Ubuntu Linux 5.4.0-131-generic

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildVoiceStates, GuildMessages, GuildMessageReactions, DirectMessages

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Jiralite commented Nov 6, 2023

To be frank, I don't think we're keen on diagnosing WebSocket-related issues in version 13 because the implementation has changed greatly from version 14 onwards. It would be better for both us and you to update to version 14 and see if you're still seeing the same error. From there, we can move forward.

@qtAmyVT
Copy link
Author

qtAmyVT commented Nov 6, 2023

To be frank, I don't think we're keen on diagnosing WebSocket-related issues in version 13 because the implementation has changed greatly from version 14 onwards. It would be better for both us and you to update to version 14 and see if you're still seeing the same error. From there, we can move forward.

The bot isn't quite ready for discord.js v14, and it is running on LTS until it is ready. Is there a minifix for my version or throw out v13 completely?

@Jiralite
Copy link
Member

Jiralite commented Nov 6, 2023

13.8.1 is quite old, even for version 13. You can try updating to 13.16.0 (there have been WebSocket-related changes since) and see if that resolves your issue.

@qtAmyVT
Copy link
Author

qtAmyVT commented Nov 6, 2023

13.8.1 is quite old, even for version 13. You can try updating to 13.16.0 (there have been WebSocket-related changes since) and see if that resolves your issue.

Alright, thanks for your help. I have one more question left: Is 13.16.0 contains any breaking changes to the code or anything I have to change or it's just mostly improvements to websocket connections?

@JMTK
Copy link
Contributor

JMTK commented Nov 6, 2023

13.8.1 is quite old, even for version 13. You can try updating to 13.16.0 (there have been WebSocket-related changes since) and see if that resolves your issue.

Alright, thanks for your help. I have one more question left: Is 13.16.0 contains any breaking changes to the code or anything I have to change or it's just mostly improvements to websocket connections?

I had the same issue as you with it appearing offline in random guilds. This fixed it for me: #9003

not sure which version this was in but it was after 13.8

@Jiralite
Copy link
Member

Jiralite commented Nov 6, 2023

That pull request landed in 13.13.0 per the milestone!

@Jiralite
Copy link
Member

Jiralite commented Nov 6, 2023

Alright, thanks for your help. I have one more question left: Is 13.16.0 contains any breaking changes to the code or anything I have to change or it's just mostly improvements to websocket connections?

We follow semantic versioning. There will be no breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants