-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
51 lines (42 loc) · 1.57 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
const Enmap = require("enmap");
const Discord = require("discord.js");
const fs = require("fs");
const db = require("quick.db");
const client = new Discord.Client();
const config = require("./config.json");
client.commands = new Enmap();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
// Load the command file itself
let props = require(`./commands/${file}`);
// Get just the command name from the file name
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
// Here we simply store the whole thing in the command Enmap. We're not running it right now.
client.commands.set(commandName, props);
});
});
client.on("ready", () => {
console.log("ready");
});
const prefix = config.prefix
client.on("message", async message => {
if (message.author.bot) return;
let user = db.get(`blacklist_${message.author.id}`);
if(user == true) return;
// Ignore messages not starting with the prefix (in config.json)
if (message.content.indexOf(prefix) !== 0) return;
// Our standard argument/command name definition.
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
// Grab the command data from the client.commands Enmap
const cmd = client.commands.get(command);
// If that command doesn't exist, silently exit and do nothing
if (!cmd) return;
// Run the command
cmd.run(client, message, args);
});
// finally done!
client.login(config.token)