forked from LikesCantCode/hypixel-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
46 lines (38 loc) · 1.65 KB
/
commands.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
const Discord = require('discord.js');
const colors = require('./conf/colors.json');
const fs = require('fs');
module.exports = {
async initCommands(client) {
client.commands = new Discord.Collection();
const commandFiles = (await fs.promises.readdir('./handlers/commands', {
encoding: "utf-8"
})).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./handlers/commands/${file}`);
try {
client.commands.set(command.name, command);
} catch (err) {
console.error(err);
}
}
},
async execute_command(commandName, message, args, client) {
const command = client.commands.get(commandName) ||
client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command || command.notReady) return;
if(command.currentlyDisabled) return message.channel.send(`\`${command.name}\` is disabled at the current time. It will be re-enabled in the near future!`);
try {
let basicStatistics = JSON.parse(fs.readFileSync('./stats/basic.json'));
basicStatistics.commands_ran++;
fs.writeFileSync('./stats/basic.json', JSON.stringify(basicStatistics, null, 4));
command.execute(message, args, client);
} catch (error) {
console.error(error);
const embed = new Discord.MessageEmbed()
.setTitle('A Problem Occured!')
.setColor(colors.errorColor)
.addField('Error:', error)
message.channel.send(embed);
}
}
}