Logout on shutdown with ShardingManager

Hello, I am currently trying to make my bot immediately "log out" i.e., appear offline on Discord as soon as my bot process exits. I take for granted that I need to use client.destroy() for this, however when trying to implement this with the ShardingManager I get some weird behaviour where when I hit Ctrl + C the client is destroyed and then immediately re-runs, hitting Ctrl + C again stops the process but throws an exception
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
This is my current implementation
process.on('SIGINT', async () => {
logger.info('SIGINT received, shutting down...');
try {
await shardingManager.broadcastEval(async client => await client.destroy());
} finally {
process.exit(0);
}
});
process.on('SIGINT', async () => {
logger.info('SIGINT received, shutting down...');
try {
await shardingManager.broadcastEval(async client => await client.destroy());
} finally {
process.exit(0);
}
});
3 Replies
d.js toolkit
d.js toolkit4w ago
Spaxter
SpaxterOP4w ago
Is that a default option? This is my ShardingManager
const clientFile = isDev ? join(directory, 'bot.ts') : join(directory, 'bot.js');
const shardingManager = new ShardingManager(clientFile, {
token,
execArgv: isDev ? ['--import', 'tsx'] : [],
});
const clientFile = isDev ? join(directory, 'bot.ts') : join(directory, 'bot.js');
const shardingManager = new ShardingManager(clientFile, {
token,
execArgv: isDev ? ['--import', 'tsx'] : [],
});
I don't do any auto-restarts to my knowledge. Right now I'm just running the bot with tsx src/client.ts and no fancy stuff in the bot file. Alright, disabling that seems to have fixed it. Thanks
d.js toolkit
d.js toolkit4w ago
The thread owner has marked this issue as solved.

Did you find this page helpful?