forked from AriaHV/juul-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (44 loc) · 1.75 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
require('dotenv').config();
const fs = require('fs');
const Discord = require('discord.js');
const { Database } = require('./database/db.js');
const { prefixes, testingPrefixes } = require('./config.json');
const { getCommands, isBotAuthor, sendResponseCommand } = require('./utils');
const response = require('./commands/response/response');
const client = new Discord.Client();
client.database = new Database();
client.commands = getCommands();
client.prefixes = (process.env.DISCORD_TOKEN) ? prefixes : testingPrefixes;
client.once('ready', () => {
console.log('Ready!');
client.user.setPresence({ game: { name: `${prefixes[0]} help` } });
});
client.on('message', async message => {
const args = message.content.split(/ +/);
if (!client.prefixes.includes(args[0]) || message.author.bot) return;
const prefixUsed = args.shift().toLowerCase();
const commandName = args.shift().toLowerCase();
// Check for general and response commands
let command =
client.commands['general'].get(commandName)
|| client.commands['general'].find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
// Check for author commands3
if (isBotAuthor(message.author)) {
const authorCommand = client.commands['author'].get(commandName)
|| client.commands['author'].find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (authorCommand) command = authorCommand;
}
if (command) {
try {
await command.execute(message, args);
}
catch (error) {
console.error(error);
}
}
const responseCommandNames = await client.database.getResponseCommandNames();
if (responseCommandNames.rows.map(x => x.command_name).includes(commandName)) {
response.execute(message, [commandName]);
}
});
client.login(process.env.DISCORD_TOKEN || process.env.DISCORD_TESTING_TOKEN);