This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
77 lines (66 loc) · 2.89 KB
/
index.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { Manager } = require("discord-hybrid-sharding");
const config = require("./botconfig/config.json");
const colors = require("colors");
const OS = require("os");
const clusterAmount = 2;
const shardsPerCluster = 2; // suggested is: 2-8
const totalShards = clusterAmount * shardsPerCluster; // suggested is to make it that 600-900 Servers are per shard, if you want to stay safe, make it that it"s 400 servers / shard, and once it reached the ~1k mark, change the amount and restart
const manager = new Manager("./bot.js", {
token: config.token,
// shardList: [ 0, 1, 2, 3, 4, 5 ], // if only those shards on that host etc.
totalShards: totalShards, // amount or: "auto"
shardsPerClusters: shardsPerCluster || 2, // amount of shards / cluster
mode: "process", // "process" or: "worker"
respawn: true,
usev13: true,
keepAlive: {
interval: 10000,
maxMissedHeartbeats: 5,
maxClusterRestarts: 3,
}
});
manager.on("clusterCreate", cluster => {
console.log(`[SHARDING-MANAGER]: `.magenta + `Launched Cluster #${cluster.id} | ${cluster.id+1}/${cluster.manager.totalClusters} [${cluster.manager.shardsPerClusters}/${cluster.manager.totalShards} Shards]`.green)
cluster.on("death", function () {
console.log(`${colors.red.bold(`Cluster ${cluster.id} died..`)}`);
});
cluster.on("message", async (msg) => {
if(!msg._sCustom) return
if (msg.dm) {
const { interaction, message, dm, packet } = msg
await manager.broadcast({ interaction, message, dm, packet })
}
})
cluster.on("error", e => {
console.log(`${colors.red.bold(`Cluster ${cluster.id} errored ..`)}`);
console.error(e);
})
cluster.on("disconnect", function () {
console.log(`${colors.red.bold(`Cluster ${cluster.id} disconnected..`)}`);
});
cluster.on("reconnecting", function () {
console.log(`${colors.yellow.bold(`Cluster ${cluster.id} reconnecting..`)}`);
});
cluster.on("close", function (code) {
console.log(`${colors.red.bold(`Cluster ${cluster.id} close with code ${code}`)}`);
});
cluster.on("exit", function (code) {
console.log(`${colors.red.bold(`Cluster ${cluster.id} exited with code ${code}`)}`);
});
});
manager.on('clientRequest', async (message) => {
if(message._sRequest && message.songRequest){
if(message.target === 0 || message.target) {
const msg = await manager.clusters.get(message.target).request(message.raw);
message.reply(msg)
} else {
manager.clusters.forEach(async cluster => {
const msg = await cluster.request(message.raw);
message.reply(msg)
})
}
}
})
// Log the creation of the debug
manager.once("debug", (d) => d.includes("[CM => Manager] [Spawning Clusters]") ? console.log(d) : "")
manager.spawn({timeout: -1});