Please describe the problem you are having in as much detail as possible:
When using the ShardingManager, an error is returned stating that "process.send is not a function", in my understanding, this would mean the ShardClientUtil class is being spawned as a parent process and not a child process.
Include a reproducible code sample here, if possible:
modules is another file that contains all my modules inc. Discord.
const { ShardingManager } = modules.Discord;
const head = new ShardingManager(`./bot.js`, {
token: storage.auth.token
});
Error is happening here:
client.on('ready', () => { process.send({ _ready: true }); });
in the ShardClientUtil.js class.
This is the bot.js file that the ShardingManager is loading:
const head = require(`./index.js`);
const client = new head.modules.Discord.Client({
disableEveryone: true,
disabledEvents: ["TYPING_START"]
});
head.modules.fs.readdir(`./events/`, (err, files) => {
if (err) return console.error(err);
for (const file of files) {
if (!file.endsWith(".js")) continue;
let event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, head, client));
delete require.cache[require.resolve(`./events/${file}`)];
head.log(`Loaded event ${file}`);
}
});
const { CommandHandler } = head.modules.djs_commands;
let cmdHandler = new CommandHandler({
folder: __dirname + `/commands/`,
prefix: [""]
});
client.commandHandler = cmdHandler;
client.login(head.storage.auth.token);
Further details:
For further investigation a stack trace would be nice! Without it the issue is rather hard to tackle.
For further investigation a stack trace would be nice! Without it the issue is rather hard to tackle.
(node:43988) UnhandledPromiseRejectionWarning: TypeError: process.send is not a function
at Client.<anonymous> (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\sharding\ShardClientUtil.js:36:42)
at Client.emit (events.js:196:13)
at WebSocketManager.triggerClientReady (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:438:17)
at WebSocketManager.checkShardsReady (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:422:10)
at WebSocketShard.<anonymous> (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:204:14)
at WebSocketShard.emit (events.js:196:13)
at WebSocketShard.checkReady (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:458:12)
at WebSocketShard.onPacket (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:430:16)
at WebSocketShard.onMessage (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:287:10)
at WebSocket.onMessage (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:196:13)
at Receiver.receiverOnMessage (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\ws\lib\websocket.js:800:20)
at Receiver.emit (events.js:196:13)
at Receiver.dataMessage (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\ws\lib\receiver.js:423:14)
at Receiver.getData (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\ws\lib\receiver.js:353:17)
at Receiver.startLoop (G:\workspace\Bot Development\Projects\The Service Team Bot\node_modules\ws\lib\receiver.js:139:22)
Does this help?
I can not reproduce this, for reference, my code:
manager.js
const Discord = require('discord.js');
const manager = new Discord.ShardingManager('./bot.js', {
token: '<<Token>>',
});
manager.spawn();
bot.js
const Discord = require('discord.js');
const client = new Discord.Client({
disableEveryone: true,
disabledEvents: ["TYPING_START"],
});
client.on('debug', info => console.log('shard - debug:', info));
client.login('<<Token>>');
Command: node manager.js
Running 1 shard.
There is a lot of noise in your reproducible code sample, something (not) in there might be causing this somehow, please make it minimal. (This includes modules, head, and the like, for the sake of reproducing just require discord.js in-place)
(node:16540) UnhandledPromiseRejectionWarning: TypeError: process.send is not a function
at Client.<anonymous> (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\sharding\ShardClientUtil.js:37:17)
at Client.emit (events.js:327:22)
at WebSocketManager.triggerClientReady (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketManager.js:433:17)
at WebSocketManager.checkShardsReady (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketManager.js:417:10)
at WebSocketShard.<anonymous> (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketManager.js:199:14)
at WebSocketShard.emit (events.js:315:20)
at WebSocketShard.checkReady (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketShard.js:467:12)
at WebSocketShard.onPacket (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketShard.js:439:16)
at WebSocketShard.onMessage (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\User\Desktop\coldgamblingbeta - Copy\node_modules\ws\lib\event-target.js:125:16)
Reproduced.
I had this error today as well, in my case the issue was combining sharding with non-sharding on the same application.
Specifically, I have one bot account that works with shards, and multiple others that are logged in on the normal application, outside of sharding.
Disabling these non-sharded logins fixed this error, as did moving every account to its own shard manager. It feels like a weird workaround to spawn shards for single-guild bots, but it solves this issue (at least for me)
I did not test this extensively with a standalone test app for reproducibility or anything, and did not try the master branch. I only tested on my own project on discord.[email protected]
Specifically, I have one bot account that works with shards, and multiple others that are logged in on the normal application, outside of sharding.
Running multiple processes on the same application or multiple applications in one process is not a supported use case. If that's the only condition under which you can reproduce this is not a bug that will be investigated further.