From 42b13272e929bc8148c97a9c0575804c1f43a88d Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Mon, 21 Jun 2021 16:14:21 -0700 Subject: [PATCH] feat(commands): added better logging for errors --- src/index.ts | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 539f76c..56336d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,24 +14,22 @@ * You should have received a copy of the GNU General Public License * along with ArgonBot. If not, see . */ -import path from 'path'; - -require('module-alias/register'); - -import process from 'process'; -import figlet from 'figlet'; -import gradient from 'gradient-string'; -import config from 'config'; -import chalk from 'chalk'; -import { Validator } from 'jsonschema'; -import { DateTime } from 'luxon'; -import { Client, Collection } from 'discord.js'; +import type Command from '@structures/command'; +import { Defaults } from '@utils/defaults'; import { debug, error, fatal, info, verbose } from '@utils/logger'; import { ECommandRunIn, ELoggingScope } from '@utils/types'; -import { Defaults } from '@utils/defaults'; import { walkDir } from '@utils/utils'; +import chalk from 'chalk'; +import config from 'config'; +import { Client, Collection } from 'discord.js'; +import figlet from 'figlet'; +import gradient from 'gradient-string'; +import { Validator } from 'jsonschema'; +import { DateTime } from 'luxon'; +import path from 'path'; +import process from 'process'; -import type Command from '@structures/command'; +require('module-alias/register'); let isBotReady = false; const commands: Collection = new Collection(); @@ -98,7 +96,15 @@ client.on('message', async (msg) => { return; } - await findCommand.run(msg, ...args); + try { + info(`Command ${findCommand.options.name} is being ran in ${msg.guild ? msg.guild.name : 'DMs'}`, ELoggingScope.Command); + await findCommand.run(msg, ...args); + info(`Finished running ${findCommand.options.name} in ${msg.guild ? msg.guild.name : `${msg.author.username} DMs`}`, ELoggingScope.Command); + } catch(e) { + error(`An error has occurred while running ${findCommand.options.name}!\n${e.message}`, ELoggingScope.Command); + msg.reply('I\'m sorry but an error has occurred while running this command! Please file an issue to' + + ` https://code.relms.dev/Relms/ArgonBot!\n\`\`\`${e.message}\`\`\``); + } }); client.on('ready', async () => {