The Sharder

The sharder is a JavaScript file which requires the built in discord.js ShardingManager and runs your main bot file along with starting the specified amount of shards.

Your sharder.js file

To do so, we need to require the discord.js ShardingManager and use the constructor to create one with our main bot file and the amount of shards we want to launch. My main bot file is called bot.js and I will be starting three shards.

const { ShardingManager } = require('discord.js');
const manager = new ShardingManager(`${__dirname}/bot.js`, { totalShards: 3 });

manager.spawn();
manager.on('launch', shard => console.log(`Successfully launched shard ${shard.id}`));

This is what your sharder.js file should look like. You can test it by running it, and if you have a ready event in your bot.js file, you should see it along with Successfully launched shard (shard). This should happen three times if you launched three shards, because multiple instances of the bot are being created to run on certain servers.

results matching ""

    No results matching ""