index.js
1.5 KB
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 { Client, Intents } = require('discord.js');
const Discord = require("discord.js");
const { token } = require('config.json');
const fs = require('fs');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.category = ['Help', 'Stationery', 'Translate', 'Ocr'];
fs.readdirSync("./Commands/").forEach(dir => {
const Filter = fs.readdirSync(`./Commands/${dir}`).filter(f => f.endsWith(".js"));
Filter.forEach(file => {
const cmd = require(`./Commands/${dir}/${file}`);
client.commands.set(cmd.config.name, cmd);
for (let alias of cmd.config.aliases) {
client.aliases.set(alias, cmd.config.name);
}
});
});
function runCommand(command, message, args, prefix) {
if (client.commands.get(command) || client.aliases.get(command)) {
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command));
if (cmd) cmd.run(client, message, args, prefix);
}
}
client.on('messageCreate', msg => {
const prefix = "!";
if (!msg.content.startsWith(prefix)) return;
let args = msg.content.slice(prefix.length).trim().split(/ +/g);
let command = args.shift().toLowerCase();
try {
runCommand(command, msg, args, prefix);
} catch (e) {
console.error(e);
}
});
client.login(token);