From db69ac885df63aba11dbac01ee99ce78e3ef8bd5 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Apr 2022 20:07:48 +0300 Subject: [PATCH] better error output when commands fail to register --- src/middleware/rest/SlashCommandManager.js | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/middleware/rest/SlashCommandManager.js b/src/middleware/rest/SlashCommandManager.js index 3f0fb11..1dc2d0e 100644 --- a/src/middleware/rest/SlashCommandManager.js +++ b/src/middleware/rest/SlashCommandManager.js @@ -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();