diff options
author | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-11 10:22:12 -0600 |
---|---|---|
committer | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-11 10:22:12 -0600 |
commit | eab83de75de50add1b5c031f1ca9b8794634b8da (patch) | |
tree | 999c3d8ef0a63113d87edd0359fcc46fbbb58bb1 /src/listeners/commands | |
parent | 24130f0dd089c1c48907215e1eaf595da2f3b639 (diff) | |
download | tanzanite-eab83de75de50add1b5c031f1ca9b8794634b8da.tar.gz tanzanite-eab83de75de50add1b5c031f1ca9b8794634b8da.tar.bz2 tanzanite-eab83de75de50add1b5c031f1ca9b8794634b8da.zip |
add a few more util things and an error handler
Diffstat (limited to 'src/listeners/commands')
-rw-r--r-- | src/listeners/commands/CommandErrorListener.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/listeners/commands/CommandErrorListener.ts b/src/listeners/commands/CommandErrorListener.ts new file mode 100644 index 0000000..37179e7 --- /dev/null +++ b/src/listeners/commands/CommandErrorListener.ts @@ -0,0 +1,48 @@ +import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BotListener } from '../../lib/extensions/BotListener'; +import { stripIndents } from 'common-tags'; +import { Message } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; +import { TextChannel } from 'discord.js'; + +export default class CommandErrorListener extends BotListener { + constructor() { + super('error', { + emitter: 'commandHandler', + event: 'error' + }); + } + async exec( + error: Error, + message: Message, + command?: BotCommand + ): Promise<void> { + const errorNumber = Math.floor(Math.random() * 6969696969) + 69; // hehe funy numbers + const errorDevEmbed = this.client.util + .createEmbed(this.client.util.colors.error) + .setTitle(`Error # \`${errorNumber}\`: An error occurred`) + .setDescription( + stripIndents`**User:** ${message.author} (${message.author.tag}) + **Command:** ${command} + **Channel:** ${message.channel} (${message.channel.id}) + **Message:** [link](${message.url})` + ) + .addField('Error', `${await this.client.util.haste(error.stack)}`); + let errorUserEmbed: MessageEmbed; + if (command) { + errorUserEmbed = this.client.util + .createEmbed(this.client.util.colors.error) + .setTitle('An error occurred') + .setDescription( + stripIndents`Whoops! It appears like something broke. + The developers have been notified of this. If you contact them, give them code \`${errorNumber}\`. + ` + ); + } + const channel = (await this.client.channels.fetch( + this.client.config.channels.log + )) as TextChannel; + await channel.send(errorDevEmbed); + if (errorUserEmbed) await message.reply(errorUserEmbed); + } +} |