-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (47 loc) · 1.86 KB
/
index.js
File metadata and controls
62 lines (47 loc) · 1.86 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
56
57
58
59
60
61
62
const Discord = require('discord.js');
const botsettings = require('./config.json');
const bot = new Discord.Client();
const fs = require("fs");
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
// register command
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err)
let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0) {
return console.log("No commands found");
}
jsfile.forEach((f, i) => {
let pull = require(`./commands/${f}`);
bot.commands.set(pull.config.name, pull);
console.log("command " + botsettings.prefix + pull.config.name + " loaded")
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name)
console.log(`new alias loaded for ${botsettings.prefix + pull.config.name} (${botsettings.prefix + alias})`)
});
});
});
// register events
fs.readdir("./events/", (err, files) => {
if(err) console.log(err)
let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0) {
return console.log("No events found");
}
jsfile.forEach((f, i) => {
require(`./events/${f}`);
console.log(`Event ${f} loaded`)
});
});
// commandhandler
bot.on("message", async message => {
if(message.author.bot || message.channel.type === "dm") return;
let prefix = botsettings.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if(!message.content.startsWith(prefix)) return;
let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix.length)))
if(commandfile) commandfile.run(bot,message,args)
})
bot.login(botsettings.token);