From 12f57e9195b1d0696751575066ff1eb798347e9a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 4 Sep 2024 09:44:24 +0200 Subject: [PATCH] add basic sharding --- src/bot.ts | 6 ++++++ src/index.ts | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/bot.ts diff --git a/src/bot.ts b/src/bot.ts new file mode 100644 index 0000000..fbfd0c0 --- /dev/null +++ b/src/bot.ts @@ -0,0 +1,6 @@ +/** Load the app. */ +const start_app = () => { + import("./load").then((l) => l.run().catch((error) => console.error(error))); +}; + +start_app(); diff --git a/src/index.ts b/src/index.ts index fc96eb6..dd53b69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,21 @@ -/** Load the app. */ -const start_app = () => { - import("./load").then((l) => l.run().catch((error) => console.error(error))); +import { ShardingManager } from "discord.js"; + +const start_manager = () => { + const manager = new ShardingManager("./dist/bot.js", { token: process.env.TOKEN_DISCORD }); + + manager.on("shardCreate", (shard) => console.log(`Launched shard ${shard.id}`)); + + manager.spawn(); }; -// Load .env if not in prod if (process.env.NODE_ENV !== "production") { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import("dotenv").then((c) => { c.config({ path: "./config/.env" }); - start_app(); + start_manager(); }); } else { - start_app(); + start_manager(); }