feat(tickets): send thank you message in logs channel
vi v@vt3e.cat
Wed, 04 Mar 2026 17:26:12 +0000
2 files changed,
30 insertions(+),
33 deletions(-)
M
src/interactions/commands/tickets/actions.ts
→
src/interactions/commands/tickets/actions.ts
@@ -322,51 +322,47 @@ _client: Client,
interaction: ButtonInteraction, ) { await interaction.deferReply({ flags: ["Ephemeral"] }); - const id = Number(interaction.customId.split(":")[2]); - const { data: ticket, exists } = await db - .select() - .from(tickets) - .where(eq(tickets.id, id)) - .then(([result]) => ({ data: result, exists: !!result })); - - if (!exists || !ticket) { - await interaction.reply("❌ Ticket not found."); - return; - } - - if (!ticket.channelId) { + const id = Number(interaction.customId.split(":")[2]); + const { data: ticket, exists: ticketExists } = await getTicketById(null, id); + if (!ticketExists || !ticket) { logger.error( - `Ticket ${ticket.id} does not have a channelId, cannot send thank you message`, + `Ticket not found for thank you interaction, ticket ID: ${id}, guild ID: ${interaction.guildId}`, + ); + return interaction.editReply( + "⚠️ Ticket or guild data not found, cannot send thank you message.", ); - await interaction.editReply( + } + + const { data: guild, exists: guildExists } = await getGuild(ticket.guildId); + if (!guildExists || !guild || !guild.ticket_channel_id) { + logger.error(`Ticket ${ticket.id} missing guild/channel data`); + return interaction.editReply( "⚠️ Ticket data is missing channel information, cannot send thank you message.", ); - return; } try { - const channel = await _client.channels.fetch(ticket.channelId); + const channel = await _client.channels.fetch(guild.ticket_channel_id); if (!channel || !("send" in channel)) { logger.error( - `Channel with ID ${ticket.channelId} not found or is not a text channel for ticket ${ticket.id}`, + `Channel ${guild.ticket_channel_id} not found or not sendable for ticket ${ticket.id}`, ); - await interaction.editReply( + return interaction.editReply( "⚠️ Could not find the ticket channel to send the thank you message.", ); - return; } await channel.send( - "The reporter says thank you for handling this ticket! 💖", + `The reporter says thank you for handling ticket #${ticket.ticketNumber}! 💖`, ); - await interaction.editReply("A thank you message sent to the moderators!"); + return interaction.editReply("A thank you message sent to the moderators!"); } catch (error) { logger.error( error, - `Could not send thank you message to moderator for ticket ${ticket.id}`, + `Could not send thank you message for ticket ${ticket.id}`, ); - await interaction.editReply( + return interaction.editReply( "⚠️ Failed to send thank you message to the moderator.", ); }
M
src/utils/queries.ts
→
src/utils/queries.ts
@@ -91,21 +91,22 @@ };
} export async function getTicketById( - guildId: Snowflake, + guildId: Snowflake | null, id: number, ): Promise<QueryResult<Ticket, false>> { - const guild = await getGuild(guildId); - if (!guild || !guild.data.ticket_message) { - return { - exists: false, - data: null, - }; - } + // const guild = await getGuild(guildId); + // if (!guild || !guild.data.ticket_message) { + // return { + // exists: false, + // data: null, + // }; + // } const ticket = await db .select() .from(tickets) - .where(and(eq(tickets.guildId, guildId), eq(tickets.id, id))) + // .where(and(eq(tickets.guildId, guildId), eq(tickets.id, id))) + .where(eq(tickets.id, id)) .execute(); if (!ticket || ticket.length === 0) {