Fix Persist assigning deleted roles (#288)

This commit is contained in:
metal 2021-09-25 19:40:17 +01:00 committed by GitHub
parent a45b5c8ba0
commit 2d84a02d48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,10 +43,12 @@ export const LoadDataEvt = persistEvt({
return; return;
} }
const guildRoles = Array.from(pluginData.guild.roles.cache.keys());
// Check specific role permissions // Check specific role permissions
if (config.persisted_roles) { if (config.persisted_roles) {
for (const roleId of config.persisted_roles) { for (const roleId of config.persisted_roles) {
if (!canAssignRole(pluginData.guild, me, roleId)) { if (!canAssignRole(pluginData.guild, me, roleId) && guildRoles.includes(roleId)) {
pluginData.getPlugin(LogsPlugin).logBotAlert({ pluginData.getPlugin(LogsPlugin).logBotAlert({
body: `Missing permissions to assign role \`${roleId}\` in persist plugin`, body: `Missing permissions to assign role \`${roleId}\` in persist plugin`,
}); });
@ -57,7 +59,7 @@ export const LoadDataEvt = persistEvt({
const persistedRoles = config.persisted_roles; const persistedRoles = config.persisted_roles;
if (persistedRoles.length) { if (persistedRoles.length) {
const rolesToRestore = intersection(persistedRoles, persistedData.roles); const rolesToRestore = intersection(persistedRoles, persistedData.roles, guildRoles);
if (rolesToRestore.length) { if (rolesToRestore.length) {
restoredData.push("roles"); restoredData.push("roles");