add basic sharding
This commit is contained in:
parent
fd60b91ffe
commit
99df64697c
2 changed files with 16 additions and 6 deletions
6
src/bot.ts
Normal file
6
src/bot.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/** Load the app. */
|
||||||
|
const start_app = () => {
|
||||||
|
import("./load").then((l) => l.run().catch((error) => console.error(error)));
|
||||||
|
};
|
||||||
|
|
||||||
|
start_app();
|
16
src/index.ts
16
src/index.ts
|
@ -1,17 +1,21 @@
|
||||||
/** Load the app. */
|
import { ShardingManager } from "discord.js";
|
||||||
const start_app = () => {
|
|
||||||
import("./load").then((l) => l.run().catch((error) => console.error(error)));
|
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") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import("dotenv").then((c) => {
|
import("dotenv").then((c) => {
|
||||||
c.config({ path: "./config/.env" });
|
c.config({ path: "./config/.env" });
|
||||||
|
|
||||||
start_app();
|
start_manager();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
start_app();
|
start_manager();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue