-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
76 lines (57 loc) · 2.15 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
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
const botconfig = require("./botconfig.json");
const token = require("./token.json"); // Create a json file with {value: yourToken}
const Discord = require("discord.js");
const fs = require("fs");
let statsController = require("./utils/eventsController.js");
let cooldown = new Set();
let cdseconds = 3;
const bot = new Discord.Client({disableEveryone: true})
bot.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("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});
});
bot.on("ready", async () => {
console.log('${bot.user.username} is online!')
console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`)
bot.user.setActivity("~help", {type: "Bot being developed!"})
});
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type == "dm") return;
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"))
if(!prefixes[message.guild.id]){
prefixes[message.guild.id] = {
prefixes: botconfig.prefix
};
}
let prefix = prefixes[message.guild.id].prefixes;
if(!message.content.startsWith(prefix)) return;
statsController.randomXP(message)
if(cooldown.has(message.author.id)){
message.delete();
return message.reply("You have to wait 3 seconds between commands.")
}
if(!message.member.hasPermission("ADMINISTRATOR")){
cooldown.add(message.author.id);
}
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
console.log(cmd + " command used by " + message.author.id + " with args: " + args)
let commandfile = bot.commands.get(cmd.slice(prefix.length))
if(commandfile) commandfile.run(bot,message,args)
setTimeout(() => {
cooldown.delete(message.author.id)
}, cdseconds * 1000)
});
bot.login(token.value);