diff --git a/src/commands/misc/archive.ts b/src/commands/misc/archive.ts index 6f6c148..349a8eb 100644 --- a/src/commands/misc/archive.ts +++ b/src/commands/misc/archive.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { CategoryChannelResolvable, ChannelType, Client, CommandInteraction, EmbedBuilder, NonThreadGuildBasedChannel } from 'discord.js'; +import { ChannelType, Client, CommandInteraction, EmbedBuilder, NonThreadGuildBasedChannel } from 'discord.js'; import '../../modules/string'; import { getLocale, getLocalizations } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; @@ -71,15 +71,17 @@ export default { // Create/Retrieve the archive category const catArchivedName = 'archive - ' + desiredCat; - const getCatArchived = () => channelGuild + const catArchivedMap = channelGuild .filter(chan => chan?.type == ChannelType.GuildCategory) .filter(chan => chan?.name == catArchivedName); - if (getCatArchived().size == 0) { - await interaction.guild?.channels + let catArchived: NonThreadGuildBasedChannel | null | undefined; + if (catArchivedMap.size > 0) { + catArchived = catArchivedMap.at(0); + } else { + catArchived = await interaction.guild?.channels .create({ name: catArchivedName, type: ChannelType.GuildCategory }); } - const catArchived = getCatArchived().at(0); const allChannelDesired = channelGuild .filter(chan => chan?.type == 0) @@ -99,7 +101,7 @@ export default { }); } - // Move channels to the archived category + // Move channels to the archived categoryx allChannelDesired.forEach(elem => elem?.setParent(catArchived?.id as string)); return interaction.reply({ @@ -107,11 +109,11 @@ export default { new EmbedBuilder() .setColor('Blurple') .setTitle(loc.get('c_archive4') - + '`' + + ' `' + catToArchive.map(cat => cat?.name) - + '`' + + '` ' + loc.get('c_archive5') - + '`' + + ' `' + catArchivedName + '`') .setDescription(