-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcluster.js
More file actions
82 lines (70 loc) · 2.25 KB
/
cluster.js
File metadata and controls
82 lines (70 loc) · 2.25 KB
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
78
79
80
81
82
const { ClusterManager } = require("discord-hybrid-sharding");
const chalk = require("chalk");
const OS = require("os");
const config = require("./config.json");
const manager = new ClusterManager(`./src/index.js`, {
totalShards: 1, // or 'auto'
shardsPerClusters: 1,
mode: "process", // you can also choose "worker"
token: process.env.TOKEN,
respawn: true,
});
manager.on("clusterCreate", (cluster) => {
console.log(
`${chalk.magenta("[SHARDING-MANAGER]:")} Launched Cluster #${
cluster.id
} | ${cluster.id + 1}/${cluster.manager.totalClusters} [${
cluster.manager.shardsPerClusters
}/${cluster.manager.totalShards} Shards]`.green,
);
cluster.on("death", function () {
console.log(chalk.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(chalk.red.bold(`Cluster ${cluster.id} errored..`));
console.error(e);
});
cluster.on("disconnect", function () {
console.log(chalk.red.bold(`Cluster ${cluster.id} disconnected..`));
});
cluster.on("reconnecting", function () {
console.log(chalk.yellow.bold(`Cluster ${cluster.id} reconnecting..`));
});
cluster.on("close", function (code) {
console.log(
chalk.red.bold(`Cluster ${cluster.id} closed with code ${code}`),
);
});
cluster.on("exit", function (code) {
console.log(
chalk.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 });