From d71379f755684867b4ce194c5048b9b7eed6f746 Mon Sep 17 00:00:00 2001 From: bodombeach Date: Sat, 6 Jul 2024 12:14:40 +0200 Subject: [PATCH] fix regression on archive method --- src/utils/archive.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/utils/archive.js b/src/utils/archive.js index 51043ad..fdd3ee3 100644 --- a/src/utils/archive.js +++ b/src/utils/archive.js @@ -5,13 +5,11 @@ async function archive(channel) { channel.type === 4 && channel.name.slice(0, 11).toLowerCase() === "📁archives_" ); - const latestCategory = channel.guild.channels.cache - .filter( - (channel) => - channel.type === 4 && - channel.name.slice(0, 11).toLowerCase() === "📁archives_" + const latestCategory = archiveCategories + .filter((channel) => channel.children.cache.size < 3) + .sort( + (a, b) => parseInt(a.name.split("_")[1]) - parseInt(b.name.split("_")[1]) ) - .sort((channel) => parseInt(channel.name.split("_")[1])) .last(); if (latestCategory) { @@ -21,12 +19,12 @@ async function archive(channel) { const count = Math.max( ...archiveCategories.map((cat) => parseInt(cat.name.split("_")[1])) ); - latestCategory = await channel.guild.channels.create({ + let newCategory = await channel.guild.channels.create({ name: `📁ARCHIVES_${count + 1}`, type: 4, }); - console.log("Created new archive latestCategory"); - channel.setParent(available_archive); + console.log(`Created new archive category ${newCategory.name}`); + channel.setParent(newCategory); } }