thaldrin/src/client/Client.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-01-19 23:35:54 +00:00
const {
Client,
Collection
} = require('discord.js');
const {
readdirSync: read
} = require('fs');
2019-11-10 08:42:09 +00:00
const server = require('../../Dashboard/server');
2019-10-14 11:19:41 +00:00
module.exports = class Thaldrin extends Client {
2019-11-10 08:42:09 +00:00
constructor(config, shards) {
super({
disableEveryone: true,
2020-01-19 23:35:54 +00:00
disabledEvents: ['TYPING_START'],
2019-11-10 08:42:09 +00:00
shardCount: shards,
totalShardCount: shards
});
this.commands = new Collection();
this.cooldowns = new Collection();
// this.queues = new Collection();
this.config = config;
this.lastEval = null;
this.login(config.token);
this.load();
}
async load() {
const events = await read('./DiscordEvents');
const modules = await read('./DiscordModules');
server(this);
events.filter((f) => f.endsWith('.js')).forEach((file) => {
try {
const event = require(`../../DiscordEvents/${file}`);
this.on(event.name, event.run.bind(null, this));
} catch (err) {
console.error(err);
}
});
modules.filter((f) => !f.endsWith('.js')).forEach(async (module) => {
const commands = await read(`./DiscordModules/${module}`);
commands.filter((f) => f.endsWith('.js')).forEach((command) => {
try {
const file = require(`../../DiscordModules/${module}/${command}`);
const Command = new file();
this.commands.set(Command.name, Command);
} catch (err) {
console.error(err);
}
});
});
}
2020-01-19 23:35:54 +00:00
};