-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.29 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
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.Client();
const config = require("./config.json");
const fetch = require('node-fetch');
client.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0) {
console.log(new Error("An error occurred!"));
process.exit(1);
return;
}
jsfile.forEach((f) =>{
let props = require(`./commands/${f}`);
console.log(`Loaded ${f}.`);
client.commands.set(props.help.name, props);
});
})
if (process.version.slice(1).split('.')[0] < 8) {
console.log(new Error(`You must have NodeJS 12.x or higher installed on your PC.`));
process.exit(1);
};
client.login(config.token)
client.on('ready', () => {
console.log("I'm online")
});
client.on("message", (message) => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.toLowerCase().split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if(!message.content.startsWith(config.prefix)) return;
let commandfile = client.commands.get(cmd.slice(config.prefix.length));
if(commandfile) commandfile.run(client,message,args);
});