-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 2.08 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
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const { dao } = require('./db/dao');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', async () => {
await dao.initSchema();
await dao.sync();
await dao.initDb();
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) {
return;
}
const args = message.content.slice(prefix.length).split(/ +/);
const commandName = args.shift().toLocaleLowerCase();
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if(!command) {
return;
}
if(command.authorizedUsers && !command.authorizedUsers.includes(message.author.id)) {
return message.reply('You are not authorized to use that command');
}
if(command.authorizedChannels && !command.authorizedChannels.includes(message.channel.name)) {
return message.reply(`You can only execute this command in one of the following channels: ${command.authorizedChannels.join(', ')}`);
}
if (command.args && !args.length) {
let reply = 'You didn\'t provide any arguments! See the proper usages below:';
if(command.usage) {
for (var i = 0; i < command.usage.length; i++) {
reply += `\n\t'${prefix}${command.name} ${command.usage[i]}`;
}
}
return message.reply(reply);
}
try {
command.execute(message, args, commandName);
}
catch (error) {
console.error(error);
message.reply('OOPSIE WOOPSIE!! Uwu We make a fucky wucky!! A wittle fucko boingo! <@259396529016537088> is working VEWY HAWD to fix this!');
}
});
client.login(token);