-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (35 loc) · 1.26 KB
/
index.js
File metadata and controls
47 lines (35 loc) · 1.26 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
const Discord = require("discord.js")
const config = require("./config.json")
const bot = new Discord.Client();
const fs = require("fs");
bot.commands = new Discord.Collection();
if(config.token === "setmeplease") return console.log("Set your token up! Go to https://www.discordapp.com/developers and generate a token from a bot user.");
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", () => {
console.log(bot.user.username + " is online.")
});
bot.on("message", async message => {
//a little bit of data parsing/general checks
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
let content = message.content.split(" ");
let command = content[0];
let args = content.slice(1);
let prefix = config.prefix;
//checks if message contains a command and runs it
let commandfile = bot.commands.get(command.slice(prefix.length));
if(commandfile) commandfile.run(bot,message,args);
})
bot.login(config.token)