eximiabots-radiox/struct/client.js

46 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-02 19:38:42 +00:00
const { Client, Collection } = require('discord.js');
const Discord = require('discord.js');
const fs = require('fs');
2020-03-08 23:26:24 +00:00
const path = require('path');
2020-03-02 19:38:42 +00:00
const events = '../events/';
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.radio = new Map();
this.funcs = {};
this.dispatcher = {};
2020-03-12 22:53:23 +00:00
this.config = require('../config.js');
this.messages = require('./messages.js');
2020-03-12 09:59:05 +00:00
this.funcs.check = require('./check.js');
2020-03-02 19:38:42 +00:00
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
command.uses = 0;
this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command);
}
this.on('ready', () => {
require(`${events}ready`).execute(this, Discord);
});
this.on('message', (msg) => {
require(`${events}msg`).execute(this, msg, Discord);
});
2020-03-07 20:07:54 +00:00
this.on('voiceStateUpdate', (oldState, newState) => {
require(`${events}voiceStateUpdate`).execute(this, oldState, newState);
2020-03-02 19:38:42 +00:00
});
this.on('error', (error) => {
2020-03-12 09:59:05 +00:00
console.error(error);
2020-03-02 19:38:42 +00:00
});
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};