File size: 885 Bytes
4e3fbe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { ShardingManager, Events } from "discord.js";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Logger, LogLevel } from "meklog";
import dotenv from "dotenv";

dotenv.config();

const production = process.env.NODE_ENV == "prod" || process.env.NODE_ENV == "production";
const log = new Logger(production, "Shard Manager");

log(LogLevel.Info, "Loading");

const filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), "bot.js");
const manager = new ShardingManager(filePath, { token: process.env.TOKEN });

manager.on("shardCreate", async shard => {
	const shardLog = new Logger(production, `Shard #${shard.id}`);

	shardLog(LogLevel.Info, "Created shard");

	shard.once(Events.ClientReady, async () => {
		shard.send({ shardID: shard.id, logger: shardLog.data });

		shardLog(LogLevel.Info, "Shard ready");
	});
});

manager.spawn();