feat(tickets): gracefully handle when users have DMs closed
vi v@vt3e.cat
Wed, 25 Mar 2026 23:06:02 +0000
1 files changed,
15 insertions(+),
5 deletions(-)
M
src/interactions/commands/tickets/actions.ts
→
src/interactions/commands/tickets/actions.ts
@@ -18,6 +18,7 @@ ChannelType,
type ChatInputCommandInteraction, type Client, ContainerBuilder, + DiscordAPIError, type GuildMember, type ModalSubmitInteraction, PermissionFlagsBits,@@ -151,6 +152,7 @@ await interaction.editReply("❌ This ticket is already closed.");
return; } const closedByReporter = interaction.user.id === _ticket.authorId; + const isManager = hasManagerPermissions(interaction.member as GuildMember); const channel = interaction.channel; if (!channel || !("permissionOverwrites" in channel)) return;@@ -188,7 +190,7 @@
const isAdmin = member?.permissions.has(PermissionFlagsBits.Administrator); const isOwner = interaction.guild?.ownerId === ticket.authorId; - if (!isAdmin && !isOwner) { + if (!isAdmin && !isOwner && !isManager) { await channel.permissionOverwrites.edit(ticket.authorId, { ViewChannel: false, });@@ -260,10 +262,18 @@ users: [],
}, }); } catch (error) { - logger.error( - error, - `Could not send DM to user ${ticket.authorId} for closed ticket ${ticket.id}`, - ); + if ( + error instanceof DiscordAPIError && + [50007, 50278].includes(error.code as number) + ) { + channel.send(`Couldn't DM the reporter, they may have DMs disabled.`); + } else { + channel.send("Couldn't DM the reporter."); + logger.error( + error, + `Could not send DM to user ${ticket.authorId} for closed ticket ${ticket.id}`, + ); + } } };