Button error

anybody knows why this is happening? So I have a ticketing system that just stopped working now, for some ungodly reason, closing the ticket takes ages, it will not close it and then error out.
2024-03-30 20:58:07 - ERROR - Encountered error while handling an interaction handler run method for interaction-handler "ticketClose" at path "/home/container/src/interaction-handlers/ticket/ticketClose.js" TypeError: Cannot read properties of null (reading 'delete')
2024-03-30 20:58:07 - ERROR - Encountered error while handling an interaction handler run method for interaction-handler "ticketClose" at path "/home/container/src/interaction-handlers/ticket/ticketClose.js" TypeError: Cannot read properties of null (reading 'delete')
Code:
interaction.reply({ content: "Closing..." })
const ticketChannel = interaction.channel;
const ticketOwnerId = ticketChannel.topic;
const ticketOwner = await this.container.client.users.fetch(ticketOwnerId);
const logs = interaction.guild.channels.cache.get(config.ticket_logs);
const attachment = await createTranscript(ticketChannel, {
limit: -1,
returnBuffer: false,
fileName: `${ticketChannel.name}.html`,
poweredBy: "Ticker Bots"
})
let summary = {};
ticketChannel.messages.cache.map(message => {
if (summary.hasOwnProperty(message.author.id))
summary[message.author.id].number++;
else
summary[message.author.id] = { number: 0, user: message.author };
});
let amount = "";
for (let user in summary) {
amount += `\`${summary[user].number + 1}\` - ${summary[user].user.tag}\n(${summary[user].user.id})\n`;
}

let key = Object.keys(summary).sort((a, b) => summary[b].number - summary[a].number)[0];
const logEmbed = new EmbedBuilder()
.setColor('Random')
.setTitle(`Ticket Closed`)
.addFields({ name: `Ticket Name:`, value: `**\`${ticketChannel.name}\`(${ticketChannel})**`, inline: false })
.addFields({ name: `Ticket Owner:`, value: `**\`${ticketOwner.username}#${ticketOwner.discriminator}\`(${ticketOwner})**`, inline: false })
.addFields({ name: `Closed By:`, value: `**\`${interaction.user.username}#${interaction.user.discriminator}\`(${interaction.user})**`, inline: false })
.addFields({ name: `Opened At:`, value: `**<t:${parseInt(ticketChannel.createdTimestamp / 1000)}:d>, <t:${parseInt(ticketChannel.createdTimestamp / 1000)}:T>\n<t:${parseInt(ticketChannel.createdTimestamp / 1000)}:R>**`, inline: false })
.addFields({ name: `Closed At:`, value: `**<t:${parseInt(Date.now() / 1000)}:d>, <t:${parseInt(Date.now() / 1000)}:T>\n<t:${parseInt(Date.now() / 1000)}:R>**`, inline: false })
.addFields({ name: `Users In ticket:`, value: `**${amount}**`, inline: false })
.addFields({ name: `Most Active:`, value: `**${summary[key].user.tag}\(${summary[key].user})**`, inline: true })
.setTimestamp();
await logs.send({ embeds: [logEmbed], files: [attachment] });
await interaction.channel.delete();
interaction.reply({ content: "Closing..." })
const ticketChannel = interaction.channel;
const ticketOwnerId = ticketChannel.topic;
const ticketOwner = await this.container.client.users.fetch(ticketOwnerId);
const logs = interaction.guild.channels.cache.get(config.ticket_logs);
const attachment = await createTranscript(ticketChannel, {
limit: -1,
returnBuffer: false,
fileName: `${ticketChannel.name}.html`,
poweredBy: "Ticker Bots"
})
let summary = {};
ticketChannel.messages.cache.map(message => {
if (summary.hasOwnProperty(message.author.id))
summary[message.author.id].number++;
else
summary[message.author.id] = { number: 0, user: message.author };
});
let amount = "";
for (let user in summary) {
amount += `\`${summary[user].number + 1}\` - ${summary[user].user.tag}\n(${summary[user].user.id})\n`;
}

let key = Object.keys(summary).sort((a, b) => summary[b].number - summary[a].number)[0];
const logEmbed = new EmbedBuilder()
.setColor('Random')
.setTitle(`Ticket Closed`)
.addFields({ name: `Ticket Name:`, value: `**\`${ticketChannel.name}\`(${ticketChannel})**`, inline: false })
.addFields({ name: `Ticket Owner:`, value: `**\`${ticketOwner.username}#${ticketOwner.discriminator}\`(${ticketOwner})**`, inline: false })
.addFields({ name: `Closed By:`, value: `**\`${interaction.user.username}#${interaction.user.discriminator}\`(${interaction.user})**`, inline: false })
.addFields({ name: `Opened At:`, value: `**<t:${parseInt(ticketChannel.createdTimestamp / 1000)}:d>, <t:${parseInt(ticketChannel.createdTimestamp / 1000)}:T>\n<t:${parseInt(ticketChannel.createdTimestamp / 1000)}:R>**`, inline: false })
.addFields({ name: `Closed At:`, value: `**<t:${parseInt(Date.now() / 1000)}:d>, <t:${parseInt(Date.now() / 1000)}:T>\n<t:${parseInt(Date.now() / 1000)}:R>**`, inline: false })
.addFields({ name: `Users In ticket:`, value: `**${amount}**`, inline: false })
.addFields({ name: `Most Active:`, value: `**${summary[key].user.tag}\(${summary[key].user})**`, inline: true })
.setTimestamp();
await logs.send({ embeds: [logEmbed], files: [attachment] });
await interaction.channel.delete();
1 Reply
Favna
Favna8mo ago
Button... Button... Do you have aggressive caching configured? Could it be the button is clicking way after created (the limit would be 15 minutes if i remember correctly) and delete is called on interaction.channel so it could be uncached by that time. Maybe try calling await interaction.channel.fetch() first?
Want results from more Discord servers?
Add your server