diff --git a/src/commands/CommandManager.js b/src/commands/CommandManager.js index 464af84c0..4243c5386 100644 --- a/src/commands/CommandManager.js +++ b/src/commands/CommandManager.js @@ -204,9 +204,14 @@ export class CommandManager { * @return {Promise} */ async handleCommandError(interaction, error) { - await logger.error(error); + const name = [ + interaction.commandName, + interaction.options.getSubcommandGroup(false), + interaction.options.getSubcommand(false) + ].filter(v => !!v).join(' '); + await logger.error(`Failed to execute command '${name}': ${error.name}`, error); let message = 'An error occurred while executing this command. '; - if (error.code === RESTJSONErrorCodes.MissingPermissions) { + if ([RESTJSONErrorCodes.MissingPermissions, RESTJSONErrorCodes.MissingAccess].includes(error.code)) { message = 'I\'m missing some permissions to execute this command. '; } diff --git a/src/discord/GuildWrapper.js b/src/discord/GuildWrapper.js index bc9c43007..ef191bcff 100644 --- a/src/discord/GuildWrapper.js +++ b/src/discord/GuildWrapper.js @@ -3,6 +3,7 @@ import RateLimiter from './RateLimiter.js'; import bot from '../bot/Bot.js'; import GuildSettings from '../settings/GuildSettings.js'; import database from '../bot/Database.js'; +import logger from '../bot/Logger.js'; export default class GuildWrapper { @@ -162,7 +163,17 @@ export default class GuildWrapper { const channel = await this.fetchChannel(channelId); if (channel && channel instanceof BaseGuildTextChannel) { - return channel.send(options); + try { + return channel.send(options); + } + catch (e) { + if ([RESTJSONErrorCodes.MissingPermissions, RESTJSONErrorCodes.MissingAccess].includes(e.code)) { + await logger.warn('Failed to send message to ' + + `${channel.name} (${channelId}) in ${this.guild.name} (${this.guild.id}): ${e.name}`, e); + } else { + throw e; + } + } } return null; }