-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (49 loc) · 1.82 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
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
/* eslint-disable no-param-reassign */
require('dotenv').config();
const Discord = require('discord.js');
const fs = require('fs');
const { LocaleDb } = require('informa-db.js');
const keys = new LocaleDb({ path: 'all_keys.json' });
const highlights = {
keys,
};
const client = new Discord.Client();
const commands = Object.fromEntries(
fs
.readdirSync('commands')
.map((v) => [v.replace('.js', ''), require(`./commands/${v}`)]),
);
client.on('message', async (msg) => {
if (!msg.content.startsWith(process.env.PREFIX)) return null;
const [command, ...args] = msg.content
.substring(process.env.PREFIX.length)
.split(' ');
if (command.toLowerCase() in commands) {
if (commands[command].admin) {
if (msg.member.hasPermission('ADMINISTRATOR')) await commands[command].fn(msg, args, client, highlights);
else msg.channel.send('Insufficient permission [Required: `Admin`]');
} else if (commands[command].owner === 'bot') {
if (msg.author.id === (await client.fetchApplication()).owner.id) {
await commands[command].fn(msg, args, client, highlights);
} else {
msg.channel.send(`Command ${process.env.PREFIX}${command} not found`);
}
} else if (commands[command].owner === 'server') {
if (msg.author.id === msg.guild.ownerID) {
await commands[command].fn(msg, args, client, highlights);
} else {
msg.channel.send('Insufficient permision [Required: `Server owner`]');
}
} else {
await commands[command].fn(msg, args, client, highlights);
}
} else {
msg.channel.send(`Command ${process.env.PREFIX}${command} not found`);
}
return 'there';
});
client.on('ready', () => console.log(`----------
Ready player 1`));
client.login(process.env.TOKEN);