Counting Deleted Channels

Hello. I have a ModMail bot. I've successfully got the bot to count posted channels (tickets), but I don't know how to get the bot to count closed tickets (the channels get deleted). How do I do that? Here's my channelDelete event. Thanks.
2 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
sky
skyOP17mo ago
client.on('channelDelete', async (channel) => {
const guild = client.guilds.cache.get(client.main_db.get('guild'));

if (!guild) return;

const category = guild.channels.cache.get(client.main_db.get('category'));

if (channel.type !== ChannelType.GuildText) return;
if ((channel as TextChannel).parentId !== category.id) return;

const ticketsCategoryChannel = client.channels.cache.get(category.id) as CategoryChannel
const numTickets = ticketsCategoryChannel.children.cache.size;
const numClosed = !ticketsCategoryChannel.children.cache.size;
const channel1 = guild.channels.cache.find((channel) => channel.name === client.user.id && channel.parentId === category.id && channel.type === ChannelType.GuildText);
const channel2 = client.channels.cache.get('1127093969164177478') as TextChannel;

const ticketsEmbedMessage = channel2.messages.cache.get(ticketsEmbedMessageId);
await ticketsEmbedMessage.edit({
embeds: [
new EmbedBuilder()
.setAuthor({
name: "ModMail",
iconURL: client.user.displayAvatarURL()
})
.setTitle("ModMail Stats")
.setDescription("Status: **`✅` Online**")
.addFields(
{ name: 'Open Tickets', value: "✅ " + `${numTickets}` },
{ name: 'Resolved Tickets', value: "❌ " + `${numClosed}`}
)
.setColor('Blurple')
.setImage(client.user.avatarURL())
]
});


const user = client.users.cache.get(channel.name);

if (!user) return;

user.send({
embeds: [
warningEmbed('Your mail has been deleted. Please do not send any message, now, to avoid creating new mail for no reason.')
]
}).catch(() => { });
});
client.on('channelDelete', async (channel) => {
const guild = client.guilds.cache.get(client.main_db.get('guild'));

if (!guild) return;

const category = guild.channels.cache.get(client.main_db.get('category'));

if (channel.type !== ChannelType.GuildText) return;
if ((channel as TextChannel).parentId !== category.id) return;

const ticketsCategoryChannel = client.channels.cache.get(category.id) as CategoryChannel
const numTickets = ticketsCategoryChannel.children.cache.size;
const numClosed = !ticketsCategoryChannel.children.cache.size;
const channel1 = guild.channels.cache.find((channel) => channel.name === client.user.id && channel.parentId === category.id && channel.type === ChannelType.GuildText);
const channel2 = client.channels.cache.get('1127093969164177478') as TextChannel;

const ticketsEmbedMessage = channel2.messages.cache.get(ticketsEmbedMessageId);
await ticketsEmbedMessage.edit({
embeds: [
new EmbedBuilder()
.setAuthor({
name: "ModMail",
iconURL: client.user.displayAvatarURL()
})
.setTitle("ModMail Stats")
.setDescription("Status: **`✅` Online**")
.addFields(
{ name: 'Open Tickets', value: "✅ " + `${numTickets}` },
{ name: 'Resolved Tickets', value: "❌ " + `${numClosed}`}
)
.setColor('Blurple')
.setImage(client.user.avatarURL())
]
});


const user = client.users.cache.get(channel.name);

if (!user) return;

user.send({
embeds: [
warningEmbed('Your mail has been deleted. Please do not send any message, now, to avoid creating new mail for no reason.')
]
}).catch(() => { });
});
How do I do that?
Want results from more Discord servers?
Add your server