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; let result = null;
try { try {
result = await Promise.all(promises); result = await Promise.all(promises);
} catch(error) { } catch (error) {
this.client.logger.write( // Figures out which command and option ran into issues
'error', 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}` `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; if(!result) return null;
this.saveHash(); 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; return result;
} }
@ -73,22 +86,20 @@ class SlashCommandManager {
const cmdHash = hash(commands); const cmdHash = hash(commands);
const upToDate = this.hash.global === cmdHash; 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; if (upToDate) return;
this.hash.global = cmdHash; this.hash.global = cmdHash;
try { 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( await this.rest.put(
Routes.applicationCommands(clientId), Routes.applicationCommands(clientId),
{ body: commands } { 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) { } catch(error) {
this.client.logger.write('error', 'Failed to refresh slash commands globally.'); return this.client.logger.error(`Failed to refresh slash commands globally.\n${error.stack || error}`);
this.client.logger.write('error', error?.stack);
return;
} }
this.saveHash(); this.saveHash();