From 9deee06ecf01d3ea8eb7953e816a53841e31e6ae Mon Sep 17 00:00:00 2001 From: versx Date: Fri, 28 May 2021 16:05:05 -0700 Subject: [PATCH] Fix permissions issue with deleting channels --- src/index.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6c41e9b..db1184b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,6 +80,12 @@ const createVoiceChannels = async (guildInfo: any, activeEvents: any): Promise => return; } try { - await channel.delete(); + await channel.delete('Expired event'); } catch (e) { console.error(`Failed to delete channel ${channel.id}: ${e}`); } }; -const deleteExpiredEvents = (guildChannel: GuildChannel, activeEvents: any): void => { +const deleteExpiredEvents = async (eventCategoryChannel: GuildChannel, activeEvents: any): Promise => { // Check if channels in category exists in active events, if so, keep it, otherwise delete it. - const channels = (((guildChannel)).children).array(); + const channels = (((eventCategoryChannel)).children).array(); const activeEventNames = activeEvents.map((x: ActiveEvent) => formatEventName(x)); for (const channel of channels) { if (!channel) { @@ -151,7 +157,7 @@ const deleteExpiredEvents = (guildChannel: GuildChannel, activeEvents: any): voi // Check if channel does not exist in formatted active event names if (!activeEventNames.includes(channel?.name)) { // Delete channel if it's not an active event - deleteChannel(guildChannel.guild, channel?.id); + await deleteChannel(eventCategoryChannel.guild, channel?.id); } } };