From b2da972733d7690dbfc4f772baae574a2bd419f6 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 31 Oct 2022 01:34:30 +0100 Subject: [PATCH] fix unbanning in guilds the bot has been kicked from --- src/discord/GuildWrapper.js | 2 +- src/interval/UnbanInterval.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/discord/GuildWrapper.js b/src/discord/GuildWrapper.js index b42d28604..deab74fa0 100644 --- a/src/discord/GuildWrapper.js +++ b/src/discord/GuildWrapper.js @@ -35,7 +35,7 @@ export default class GuildWrapper { return new this(await bot.client.guilds.fetch(id)); } catch (e) { - if (e.code === RESTJSONErrorCodes.UnknownGuild) { + if ([RESTJSONErrorCodes.UnknownGuild, RESTJSONErrorCodes.MissingAccess].includes(e.code)) { return null; } throw e; diff --git a/src/interval/UnbanInterval.js b/src/interval/UnbanInterval.js index af5a2c51f..3a43ccd8c 100644 --- a/src/interval/UnbanInterval.js +++ b/src/interval/UnbanInterval.js @@ -21,6 +21,12 @@ export default class UnbanInterval extends Interval { /** @property {number} insertId */ const unban = await database.queryAll('INSERT INTO moderations (guildid, userid, action, created, reason, active) VALUES (?,?,?,?,?,?)', result.guildid, result.userid, 'unban', Math.floor(Date.now()/1000), reason, false); const guild = await GuildWrapper.fetch(result.guildid); + + if (!guild) { + const wrapper = new GuildWrapper({id: result.guildid}); + await wrapper.deleteData(); + } + const member = new MemberWrapper(user, guild); await database.query('UPDATE moderations SET active = FALSE WHERE action = \'ban\' AND userid = ? AND guildid = ?',result.userid, result.guildid);