This repository has been archived on 2023-08-07. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
vylbot-core/src/client/client.js
2020-10-20 10:45:24 +01:00

46 lines
No EOL
1.3 KiB
JavaScript

const { Client } = require('discord.js');
const { existsSync } = require('fs');
const events = require('./events');
const util = require('./util');
class client extends Client {
constructor(config) {
super();
this.config = config;
this.events = new events();
this.util = new util(this);
}
start() {
super.on("message", this.events.message);
super.on("ready", this.events.ready);
super.login(this._config.token);
this.util.loadEvents();
}
// Config
get config() {
return this._config;
}
set config(config) {
// Validate the config
if (this._config) throw "Config has already been set";
if (typeof config != "object") throw "Config is not a JSON object";
if (typeof config.token != "string") throw "Token is not a string";
if (typeof config.prefix != "string") throw "Prefix is not a string";
if (typeof config.commands != "string") throw "Commands is not a string";
if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist";
if (typeof config.events != "string") throw "Events is not a string";
if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist";
this._config = config;
}
}
module.exports = client;