Skip to content

Instantly share code, notes, and snippets.

@ha6000
Created February 18, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha6000/4c02c90bdfc5fe4a63ddd33b149d4d71 to your computer and use it in GitHub Desktop.
Save ha6000/4c02c90bdfc5fe4a63ddd33b149d4d71 to your computer and use it in GitHub Desktop.
/**
* @author Harry Kruger
* @copyright 2020 Harry Kruger
*/
// todo: add auto config
const dotenv = require('dotenv');
// the default client options
const clientOptionsDefaults = {
token: undefined,
logChannel: undefined
};
// error for when a log channel is provided that isent found.
class missingLogChannelError extends Error {
constructor() {
super('Log Channel not found.');
this.name = 'missingLogChannel';
};
};
const colors = {
green: 0x84ed47
}
module.exports = {
Handler: class Handler
{
/**
* Cool class
* @param Discord The discord module
*/
constructor(Discord) {
if (Discord == undefined) {
Discord = require('discord.js');
};
this.Discord = Discord;
// the embed for when the bot is ready
const logChannelReadyEmbed = new this.Discord.RichEmbed({
title: 'Bot Ready',
color: colors.green
})
class Client extends Discord.Client {
/**
* Nice class
* @param opts {ClientOptions} The options for the Client
*/
constructor(opts) {
super();
// sets unset values to defaults
this.opts = clientOptionsDefaults;
this.opts = Object.assign(this.opts, opts);
// checks if a token is provided
if (opts.token) {
this.on('ready', () => {
console.log(`${this.user.username} is ready`);
// checks if log channel is a option
if (opts.logChannel) {
// gets the log channel
const logChannel = this.channels.get(opts.logChannel.toString());
// checks if its a valid log channel
if (logChannel) {
logChannelReadyEmbed.setDescription(`${this.user.username} is ready.`);
} else {
throw new missingLogChannelError();
};
}
});
this.login(this.opts.token);
};
};
}
this.Discord.Client = Client;
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment