Skip to content

Commit 614187d

Browse files
committed
sharding time
1 parent 17579d6 commit 614187d

File tree

4 files changed

+60
-54
lines changed

4 files changed

+60
-54
lines changed

bot.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const fs = require("fs");
2+
const Discord = require("discord.js");
3+
const client = new Discord.Client();
4+
const config = require("./config.json");
5+
const { prefix } = require("./config.json");
6+
client.commands = new Discord.Collection();
7+
8+
9+
10+
11+
12+
const commandFiles = fs
13+
.readdirSync("./commands")
14+
.filter((file) => file.endsWith(".js"));
15+
16+
17+
client.once("ready", () => {
18+
console.log("My Body is ready.");
19+
});
20+
21+
for (const file of commandFiles) {
22+
const command = require(`./commands/${file}`);
23+
24+
// set a new item in the Collection
25+
// with the key as the command name and the value as the exported module
26+
client.commands.set(command.name, command);
27+
}
28+
29+
client.on("message", (message) => {
30+
function clean(text) {
31+
if (typeof text === "string")
32+
return text
33+
.replace(/@/g, "" + String.fromCharCode(8203))
34+
.replace(/@/g, "@" + String.fromCharCode(8203));
35+
else return text;
36+
}
37+
if (!message.content.startsWith(prefix) || message.author.bot) return;
38+
39+
const args = message.content.slice(prefix.length).trim().split(/ +/);
40+
const command = args.shift().toLowerCase();
41+
if (!client.commands.has(command)) return;
42+
43+
try {
44+
client.commands.get(command).execute(message, args, client);
45+
} catch (error) {
46+
console.error(error);
47+
message.channel.send(
48+
`\`An unexpected error has occured! Please try again later! Please report this to @BoredFish#4269. More technical details:\` \`\`\`xl\n${clean(
49+
error
50+
)}\n\`\`\``
51+
);
52+
}
53+
});
54+
55+
client.login(config.token);

data/enmap.sqlite-shm

0 Bytes
Binary file not shown.

index.js

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
1-
const fs = require("fs");
2-
const Discord = require("discord.js");
3-
const client = new Discord.Client();
1+
const { ShardingManager } = require('discord.js');
42
const config = require("./config.json");
5-
const { prefix } = require("./config.json");
6-
client.commands = new Discord.Collection();
3+
const manager = new ShardingManager('./bot.js', { token: config.token });
74

8-
9-
10-
11-
12-
const commandFiles = fs
13-
.readdirSync("./commands")
14-
.filter((file) => file.endsWith(".js"));
15-
16-
17-
client.once("ready", () => {
18-
console.log("My Body is ready.");
19-
});
20-
21-
for (const file of commandFiles) {
22-
const command = require(`./commands/${file}`);
23-
24-
// set a new item in the Collection
25-
// with the key as the command name and the value as the exported module
26-
client.commands.set(command.name, command);
27-
}
28-
29-
client.on("message", (message) => {
30-
function clean(text) {
31-
if (typeof text === "string")
32-
return text
33-
.replace(/@/g, "" + String.fromCharCode(8203))
34-
.replace(/@/g, "@" + String.fromCharCode(8203));
35-
else return text;
36-
}
37-
if (!message.content.startsWith(prefix) || message.author.bot) return;
38-
39-
const args = message.content.slice(prefix.length).trim().split(/ +/);
40-
const command = args.shift().toLowerCase();
41-
if (!client.commands.has(command)) return;
42-
43-
try {
44-
client.commands.get(command).execute(message, args, client);
45-
} catch (error) {
46-
console.error(error);
47-
message.channel.send(
48-
`\`An unexpected error has occured! Please try again later! Please report this to @BoredFish#4269. More technical details:\` \`\`\`xl\n${clean(
49-
error
50-
)}\n\`\`\``
51-
);
52-
}
53-
});
54-
55-
client.login(config.token);
5+
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
6+
manager.spawn();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "TheFAQMan",
33
"version": "1.0.0",
44
"description": "The FAQ bot for the ProdigyMathGameHacking Discord server",
5-
"main": "index.js",
5+
"main": "bot.js",
66
"scripts": {
77
"start": "node bot.js",
88
"dev": "nodemon bot.js"

0 commit comments

Comments
 (0)