fixed up a few commands
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
index 48d2a51..3263580 100644
--- a/src/actions/tickets/delete.ts
+++ b/src/actions/tickets/delete.ts
@@ -1,5 +1,5 @@
import { getCommandMentionByName } from '../../utils/getCommandMentionByName.js';
-import Discord, { ActionRowBuilder, ButtonBuilder, ButtonInteraction, PrivateThreadChannel, TextChannel, ButtonStyle } from "discord.js";
+import Discord, { ActionRowBuilder, ButtonBuilder, ButtonInteraction, PrivateThreadChannel, TextChannel, ButtonStyle, CategoryChannel } from "discord.js";
import client from "../../utils/client.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
@@ -142,47 +142,60 @@
async function purgeByUser(member: string, guild: string) {
- const config = await client.database.guilds.read(guild.id);
+ const config = await client.database.guilds.read(guild);
const fetchedGuild = await client.guilds.fetch(guild);
if (!config.tickets.category) return;
- const tickets = fetchedGuild.channels.cache.get(config.tickets.category);
+ const tickets: CategoryChannel | TextChannel | undefined = fetchedGuild.channels.cache.get(config.tickets.category) as CategoryChannel | TextChannel | undefined;
if (!tickets) return;
- const ticketChannels = tickets.children;
let deleted = 0;
- ticketChannels.forEach((element) => {
- if (element.type !== "GUILD_TEXT") return;
- if (element.topic.split(" ")[0] === member) {
+ if (tickets.type === Discord.ChannelType.GuildCategory) {
+ // For channels, the topic is the user ID, then the word Active
+ const category = tickets as Discord.CategoryChannel;
+ category.children.cache.forEach((element) => {
+ if (!(element.type === Discord.ChannelType.GuildText)) return;
+ if (!(((element as Discord.TextChannel).topic ?? "").includes(member))) return;
try {
element.delete();
- } catch {
- /* Errors if the channel does not exist (deleted already) */
+ deleted++;
+ } catch (e) {
+ console.error(e);
}
- deleted++;
- }
- });
- if (deleted) {
- const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger;
- const data = {
- meta: {
- type: "ticketPurge",
- displayName: "Tickets Purged",
- calculateType: "ticketUpdate",
- color: NucleusColors.red,
- emoji: "GUILD.TICKET.DELETE",
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(member, renderUser(member)),
- deletedBy: entry(null, "Member left server"),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- ticketsDeleted: deleted
- },
- hidden: {
- guild: guild.id
+ });
+ } else {
+ // For threads, the name is the users name, id, then the word Active
+ const channel = tickets as Discord.TextChannel;
+ channel.threads.cache.forEach((element: Discord.ThreadChannel) => {
+ if (!element.name.includes(member)) return;
+ try {
+ element.delete();
+ deleted++;
+ } catch (e) {
+ console.error(e);
}
- };
- log(data);
+ });
}
+ if (!deleted) return
+ const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const data = {
+ meta: {
+ type: "ticketPurge",
+ displayName: "Tickets Purged",
+ calculateType: "ticketUpdate",
+ color: NucleusColors.red,
+ emoji: "GUILD.TICKET.DELETE",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(member, renderUser(member)),
+ deletedBy: entry(null, "Member left server"),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketsDeleted: deleted
+ },
+ hidden: {
+ guild: guild
+ }
+ };
+ log(data);
}
export { purgeByUser };
\ No newline at end of file