From 44d68bf608a5a3e3b82d049a77b4d5e94f992778 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:55:04 +0300 Subject: [PATCH] fix: fix error when trying to fetch an unknown channel in role buttons --- .../src/plugins/RoleButtons/functions/applyRoleButtons.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts b/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts index b3fc76f4..bbd290a2 100644 --- a/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts +++ b/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts @@ -18,7 +18,7 @@ export async function applyRoleButtons( // Remove existing role buttons, if any if (existingSavedButtons?.channel_id) { - const existingChannel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const existingChannel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); const existingMessage = await (existingChannel?.isText() && existingChannel.messages.fetch(existingSavedButtons.message_id).catch(() => null)); if (existingMessage && existingMessage.components.length) { @@ -31,7 +31,7 @@ export async function applyRoleButtons( // Find or create message for role buttons if ("message_id" in configItem.message) { // channel id + message id: apply role buttons to existing message - const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); const messageCandidate = await (channel?.isText() && channel.messages.fetch(configItem.message.message_id).catch(() => null)); if (!messageCandidate) { @@ -54,7 +54,7 @@ export async function applyRoleButtons( return null; } - const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); if (!channel || !channel.isText()) { pluginData.getPlugin(LogsPlugin).logBotAlert({ body: `Text channel not found for role_buttons/${configItem.name}`,