Added try/catch block to named args parsing

This commit is contained in:
Isaac 2021-05-10 23:38:09 +01:00
parent d9ece4beca
commit c6dbc11424
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3

View File

@ -156,7 +156,17 @@ module.exports = class CommandManager {
let args = raw_args; let args = raw_args;
if (cmd.process_args) { if (cmd.process_args) {
args = parseArgs(cmd.args, { argv: argv(raw_args) }); try {
args = parseArgs(cmd.args, { argv: argv(raw_args) });
} catch (error) {
let help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`;
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('cmd_usage.invalid_named_args.title'))
.setDescription(i18n('cmd_usage.invalid_named_args.description', error.message, help_cmd))
);
}
for (let arg of cmd.args) { for (let arg of cmd.args) {
if (arg.required && args[arg.name] === undefined) { if (arg.required && args[arg.name] === undefined) {
return await cmd.sendUsage(message.channel, cmd_name); // send usage if any required arg is missing return await cmd.sendUsage(message.channel, cmd_name); // send usage if any required arg is missing