better error output when commands fail to register

This commit is contained in:
Erik 2022-04-29 20:07:48 +03:00
parent bce8974c95
commit db69ac885d
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -54,17 +54,30 @@ class SlashCommandManager {
let result = null;
try {
result = await Promise.all(promises);
} catch(error) {
this.client.logger.write(
'error',
} catch (error) {
// Figures out which command and option ran into issues
const invalid = error.rawError.errors;
const keys = Object.keys(invalid);
let str = '';
for (const key of keys) {
const command = commands[parseInt(key)];
str += `${command.name}: `;
const options = Object.keys(invalid[key].options);
for (const optKey of options) {
str += `${command.options[optKey].name}\t`;
}
str += `\n\n`;
}
this.client.logger.error(
`An issue has occured while updating guild commands. Guild command refresh aborted.\n${error.stack || error}`
);
this.client.logger.error(`Failed commands:\n${str}`);
}
if(!result) return null;
this.saveHash();
this.client.logger.write('debug', `Refreshed guild slash commands for guild${guilds.length === 1 ? '' : 's'}: ${guilds.join(' ')}`);
this.client.logger.debug(`Refreshed guild slash commands for guild${guilds.length === 1 ? '' : 's'}: ${guilds.join(' ')}`);
return result;
}
@ -73,22 +86,20 @@ class SlashCommandManager {
const cmdHash = hash(commands);
const upToDate = this.hash.global === cmdHash;
this.client.logger.write('info', `Commands hash: ${cmdHash}, ${upToDate?'not':''} updating`);
this.client.logger.info(`Commands hash: ${cmdHash}, ${upToDate?'not ':''}updating`);
if (upToDate) return;
this.hash.global = cmdHash;
try {
this.client.logger.write('debug', 'Starting global refresh for slash commands.');
this.client.logger.debug('Starting global refresh for slash commands.');
await this.rest.put(
Routes.applicationCommands(clientId),
{ body: commands }
);
this.client.logger.write('debug', 'Finished global refresh for slash commands.');
this.client.logger.debug('Finished global refresh for slash commands.');
} catch(error) {
this.client.logger.write('error', 'Failed to refresh slash commands globally.');
this.client.logger.write('error', error?.stack);
return;
return this.client.logger.error(`Failed to refresh slash commands globally.\n${error.stack || error}`);
}
this.saveHash();