eximiabots-radiox/client/class.js

63 lines
2.1 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-04-02 05:40:05 +00:00
const events = './events/';
const Datastore = require('./datastore.js');
2020-03-02 19:38:42 +00:00
const GatewayIntents = new Discord.Intents();
GatewayIntents.add(
1 << 0, // GUILDS
1 << 7, // GUILD_VOICE_STATES
1 << 9 // GUILD_MESSAGES
);
2020-03-02 19:38:42 +00:00
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START'],
ws: {
intents: GatewayIntents
}
2020-03-02 19:38:42 +00:00
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.radio = new Map();
2020-04-02 05:13:51 +00:00
2020-03-02 19:38:42 +00:00
this.funcs = {};
2020-04-02 05:40:05 +00:00
this.funcs.check = require('./funcs/check.js');
this.funcs.checkFetchStatus = require('./funcs/checkFetchStatus.js');
this.funcs.isDev = require('./funcs/isDev.js');
2020-04-02 05:40:05 +00:00
this.funcs.msToTime = require('./funcs/msToTime.js');
this.funcs.statisticsUpdate = require('./funcs/statisticsUpdate.js');
2020-04-02 05:13:51 +00:00
2020-04-02 07:07:27 +00:00
this.config = require('../config.js');
2020-03-12 22:53:23 +00:00
this.messages = require('./messages.js');
2020-03-02 19:38:42 +00:00
2020-04-02 07:15:08 +00:00
const commandFiles = fs.readdirSync('./client/commands/').filter(f => f.endsWith('.js'));
2020-03-02 19:38:42 +00:00
for (const file of commandFiles) {
2020-04-02 05:40:05 +00:00
const command = require(`./commands/${file}`);
2020-03-02 19:38:42 +00:00
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.datastore = new Datastore();
2020-03-02 19:38:42 +00:00
});
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));
}
};