-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
55 lines (44 loc) · 1.3 KB
/
bot.js
File metadata and controls
55 lines (44 loc) · 1.3 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
const Discord = require("discord.js");
const config = require("./config");
const { createErrorMessage } = require("./utils").messages;
const commands = require("./commands");
const help = require("./commands/help");
const client = new Discord.Client();
const prefix = config.get("prefix");
commands.set("help", help);
client.on("ready", () => {
console.log("Ready");
});
client.on("reconnecting", () => {
console.log("Reconnecting");
});
client.on("disconnect", () => {
console.log("Disconnect");
});
client.on("message", async (message) => {
if (message.author.bot || !message.content.startsWith(prefix)) return;
if (!message.guild) {
return message.channel.send(
createErrorMessage("This is not a guild channel!")
);
}
const args = message.content.trim().slice(prefix.length).split(/ +/);
message.args = args;
const commandName = args.shift();
const command = commands.get(commandName);
if (command) {
try {
await command.execute(message, client);
} catch (error) {
if (error.type === "custom") {
message.channel.send(createErrorMessage(error.message));
} else {
console.log(error);
message.channel.send(
createErrorMessage("Error...Something went wrong")
);
}
}
}
});
client.login(config.get("token"));