fix: fix/archive #56

Merged
loonatiny merged 9 commits from fix/archive into main 2023-01-17 22:05:39 +01:00
Showing only changes of commit ee642ae6e4 - Show all commits

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders'; 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 '../../modules/string';
import { getLocale, getLocalizations } from '../../utils/locales'; import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc'; import { getFilename } from '../../utils/misc';
@ -71,15 +71,17 @@ export default {
// Create/Retrieve the archive category // Create/Retrieve the archive category
const catArchivedName = 'archive - ' + desiredCat; const catArchivedName = 'archive - ' + desiredCat;
const getCatArchived = () => channelGuild const catArchivedMap = channelGuild
.filter(chan => chan?.type == ChannelType.GuildCategory) .filter(chan => chan?.type == ChannelType.GuildCategory)
.filter(chan => chan?.name == catArchivedName); .filter(chan => chan?.name == catArchivedName);
if (getCatArchived().size == 0) { let catArchived: NonThreadGuildBasedChannel | null | undefined;
await interaction.guild?.channels if (catArchivedMap.size > 0) {
catArchived = catArchivedMap.at(0);
} else {
catArchived = await interaction.guild?.channels
.create({ name: catArchivedName, type: ChannelType.GuildCategory }); .create({ name: catArchivedName, type: ChannelType.GuildCategory });
} }
const catArchived = getCatArchived().at(0);
const allChannelDesired = channelGuild const allChannelDesired = channelGuild
.filter(chan => chan?.type == 0) .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)); allChannelDesired.forEach(elem => elem?.setParent(catArchived?.id as string));
return interaction.reply({ return interaction.reply({