Shards Error while hosting discord bot

Hi everyone i have my discord bot running and i want to try and get 2 shards, i have got the shards.js file all setup but i get this error

Error: listen EADDRINUSE :::3000
at Server.setupListenHandle [as _listen2] (net.js:1286:14)
at listenInCluster (net.js:1334:12)
at Server.listen (net.js:1421:7)
at Function.listen (/rbd/pnpm-volume/1231ae95-fcb6-48e8-b4fc- 249ff6bf69a1/node_modules/.registry.npmjs.org/express/4.16.4/node_modules/express/lib/application.js:618:24)
Jump to

at Object.<anonymous> (/app/MusicBot.js:356:5)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1313:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
(node:20079) UnhandledPromiseRejectionWarning: Error: Shard 1's process exited before its Client became ready.
at Shard.once (/rbd/pnpm-volume/1231ae95-fcb6-48e8-b4fc-249ff6bf69a1/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/sharding/Shard.js:88:39)
at Object.onceWrapper (events.js:273:13)
 at Shard.emit (events.js:182:13)
 at Shard._handleExit (/rbd/pnpm-volume/1231ae95-fcb6-48e8-b4fc-249ff6bf69a1/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/sharding/Shard.js:272:10)
 at ChildProcess.emit (events.js:182:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
(node:20079) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 117)

my shards.js contains this

const Discord = require('discord.js');
const Manager = new Discord.ShardingManager('./server.js');
Manager.spawn(2);
console.log(`${Manager.totalShards} Shards`);

any help?


MOD EDIT: remove timestamps and recategorize

Hey @bullfrog098, welcome to the Glitch Forums!

I don’t know much off-hand about Discord.js’s sharding, but the error you’re seeing tells me that you’re probably trying to open more than one listener process. We only allow the port represented by process.env.PORT to be listened to (typically port 3000, but that can change under some circumstances) and if your code tried to listen to that port more than once you’ll see an error like this - basically you’re already listening to port 3000 and you’re telling your code to listen to it again.

My guess is that you’ve got code like const listener = app.listen(process.env.PORT, function() in server.js and the ShardingManager is running that code twice.

What I can’t tell you right now is how to resolve that issue with the ShardingManager. I’d be happy to take a look as soon as I can; would you be willing to share your project name? You can email it to support@glitch.com if you’d prefer to keep it private. Or perhaps someone else here has some direct experience with the ShardingManager and can offer some guidance.

7 Likes

You are a genius @cori , I tried putting the part of my code with the process.env.PORT in my shards.js and it works like a dream. Thanks for telling me it was a error with the process.env.PORT or else i would’ve never figured it out!

UnhandledPromiseRejectionWarning: Error [SHARDING_IN_PROCESS]: Shards are still being spawned.
Project name: byacar-apps-2
I am getting the same warning. I would be glad if you could help.
@cori

PLEASE don’t bump threads. Make your own. My iPad is legit suggesting this phrase every time I type please. :frowning: