fix getter of archived category

This commit is contained in:
Mylloon 2023-01-17 15:46:09 +01:00
parent cb00362a82
commit ee642ae6e4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

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({