-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (40 loc) · 1.96 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
const discord = require('discord.js');
const fs = require('fs');
const db = require('wio.db');
const client = new discord.Client();
const config = require('./config.json')
client.commands = new discord.Collection();
client.aliases = new discord.Collection();
client.queue = new Map();
client.on("ready", async () => {
console.log(`Bot Is Ready To Go - ${client.user.tag}`);
});
const Categories = ["mod", "misc"]; //Commands => Category => Command
Categories.forEach(async function(Category) { //
fs.readdir(`./commands/${Category}`, async function(error, files) {
if (error) throw new Error(`Error In Command - Command Handler\n${error}`);
files.forEach(async function(file) {
if (!file.endsWith(".js")) throw new Error(`A File Does Not Ends With .js - Command Handler!`);
let command = require(`./commands/${Category}/${file}`);
if (!command.name || !command.aliases) throw new Error(`No Command Name & Command Aliases In A File - Command Handler!`);
if (command.name) client.commands.set(command.name, command);
if (command.aliases) command.aliases.forEach(aliase => client.aliases.set(aliase, command.name));
if (command.aliases.length === 0) command.aliases = null;
});
});
});
client.on("message", async message => {
let Prefix = config.prefix;
if (message.author.bot || !message.guild || message.webhookID) return;
if (!message.content.startsWith(Prefix)) return;
let args = message.content.slice(Prefix.length).trim().split(/ +/g);
let cmd = args.shift().toLowerCase();
let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));
if (!command) return console.log(`No Command Found!`);
const Allowed = await db.fetch(`CommandOn_${message.guild.id}_${cmd.toLowerCase()}`);
if (Allowed !== null) return;
if (command) {
command.run(client, message, args);
};
});
client.login(process.env.TOKEN).catch(err => console.log(`Invalid Token Provided!`));