Archived
0
0
Fork 0

feat(commands): added better logging for errors

This commit is contained in:
Daryl Ronningen 2021-06-21 16:14:21 -07:00
parent d6b2470a8b
commit 42b13272e9
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B

View file

@ -14,24 +14,22 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>. * along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/ */
import path from 'path'; import type Command from '@structures/command';
import { Defaults } from '@utils/defaults';
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 { debug, error, fatal, info, verbose } from '@utils/logger'; import { debug, error, fatal, info, verbose } from '@utils/logger';
import { ECommandRunIn, ELoggingScope } from '@utils/types'; import { ECommandRunIn, ELoggingScope } from '@utils/types';
import { Defaults } from '@utils/defaults';
import { walkDir } from '@utils/utils'; 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; let isBotReady = false;
const commands: Collection<string, Command> = new Collection(); const commands: Collection<string, Command> = new Collection();
@ -98,7 +96,15 @@ client.on('message', async (msg) => {
return; return;
} }
try {
info(`Command ${findCommand.options.name} is being ran in ${msg.guild ? msg.guild.name : 'DMs'}`, ELoggingScope.Command);
await findCommand.run(msg, ...args); 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 () => { client.on('ready', async () => {