Skip to content

Commit

Permalink
Catch some permissions errors in auto mod manager
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianVennen committed Jun 14, 2024
1 parent 115940c commit 3861787
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/automod/AutoModManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ChannelSettings from '../settings/ChannelSettings.js';
import {formatTime} from '../util/timeutils.js';
import RepeatedMessage from './RepeatedMessage.js';
import SafeSearch from './SafeSearch.js';
import logger from '../bot/Logger.js';

export class AutoModManager {
#safeSearchCache;
Expand Down Expand Up @@ -109,7 +110,16 @@ export class AutoModManager {
* @return {Promise<true>}
*/
async #deleteAndWarn(message, reason, warning) {
await bot.delete(message, reason);
try {
await bot.delete(message, reason);
} catch (e) {
if (e.code !== RESTJSONErrorCodes.MissingPermissions) {
throw e;
}
const channel = /** @type {import('discord.js').GuildTextBasedChannel} */ message.channel;
await logger.warn(`Missing permissions to delete message in channel ${channel?.name} (${message.channelId}) of guild ${message.guild?.name} (${message.guildId})`, e);
return true;
}
await this.#sendWarning(message, warning);
return true;
}
Expand All @@ -121,9 +131,15 @@ export class AutoModManager {
* @return {Promise<void>}
*/
async #sendWarning(message, warning) {
const response = await (/** @type {import('discord.js').TextBasedChannelFields} */ message.channel)
.send(userMention(message.author.id) + ' ' + warning);
await bot.delete(response, null, this.#RESPONSE_TIMEOUT);
try {
const response = await (/** @type {import('discord.js').TextBasedChannelFields} */ message.channel)
.send(userMention(message.author.id) + ' ' + warning);
await bot.delete(response, null, this.#RESPONSE_TIMEOUT);
} catch (e) {
if (e.code !== RESTJSONErrorCodes.MissingPermissions) {
throw e;
}
}
}

/**
Expand Down

0 comments on commit 3861787

Please sign in to comment.