From b5be5c7d28a13a125c935cb1eb12ba48fb0309e1 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Tue, 14 Apr 2020 21:33:58 -0400 Subject: [PATCH] wrap messageCreate event in try/catch block --- src/events/messageCreate.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index d56afb9..44d5474 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -10,13 +10,18 @@ export default class { } public async run(message: Message) { - if (message.author.bot) return; - if (message.content.indexOf(this.client.config.prefix) !== 0) return; - const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); - const resolved = await this.client.util.resolveCommand(noPrefix); - if (!resolved) return; - if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return; - if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; } - await resolved.cmd.run(message, resolved.args); + try { + if (message.author.bot) return; + if (message.content.indexOf(this.client.config.prefix) !== 0) return; + const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); + const resolved = await this.client.util.resolveCommand(noPrefix); + if (!resolved) return; + if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return; + if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; } + this.client.util.signale.info(`User '${message.author.username}#${message.author.discriminator}' ran command '${resolved.cmd.name}' in '${message.channel.id}'.`); + await resolved.cmd.run(message, resolved.args); + } catch (err) { + this.client.util.handleError(err, message); + } } }