-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (37 loc) · 1.41 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
// Dependencies
const { Client, Collection } = require('discord.js'),
{ botconfig } = require('./config'),
bot = new Client({ intents: ['GUILDS', 'GUILD_MEMBERS', 'GUILD_BANS', 'GUILD_EMOJIS_AND_STICKERS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'DIRECT_MESSAGES', 'GUILD_VOICE_STATES', 'GUILD_INVITES'] }),
{ promisify } = require('util'),
readdir = promisify(require('fs').readdir),
path = require('path');
(async () => {
bot.aliases = new Collection();
bot.commands = new Collection();
bot.interactions = new Collection();
bot.cooldowns = new Collection();
bot.config = require('./config');
bot.mongoose = require('./database/mongoose');
await loadCommands();
await loadEvents();
bot.login(botconfig.token).catch(e => bot.logger.error(e.message));
})();
async function loadCommands() {
const commands = (await readdir('./bot/commands/')).filter((v, i, a) => a.indexOf(v) === i);
for (const command of commands) {
const cmd = new (require(`./bot/commands/${command}`))(bot);
bot.commands.set(cmd.help.name, cmd);
cmd.help.aliases.forEach((alias) => {
bot.aliases.set(alias, cmd.help.name);
});
}
}
async function loadEvents() {
const events = await readdir('./bot/events/');
for (const file of events) {
delete require.cache[file];
const { name } = path.parse(file);
const event = new (require(`./bot/events/${file}`))(bot, name);
bot.on(name, (...args) => event.run(bot, ...args));
}
}