Skip to content

Commit 2d4ac80

Browse files
committed
✨ tweak: enhance thread creation
1 parent 38634a2 commit 2d4ac80

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/events/interactionCreate.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @module events/interactionCreate
1414
*/
1515

16-
import { Events, MessageFlags, Interaction, CommandInteraction, ModalSubmitInteraction, EmbedBuilder } from 'discord.js';
16+
import { Events, MessageFlags, ChannelType, Interaction, CommandInteraction, ModalSubmitInteraction, EmbedBuilder } from 'discord.js';
1717
import { createTicket, bindTicketWithThread } from '../services/unthread';
1818
import { LogEngine } from '../config/logger';
1919
import { setKey } from '../utils/memory';
@@ -127,10 +127,21 @@ async function handleSupportModal(interaction: ModalSubmitInteraction): Promise<
127127
throw new Error('This command must be used in a text channel that supports threads');
128128
}
129129

130-
thread = await interaction.channel.threads.create({
131-
name: `ticket-#${ticketObj.friendlyId}`,
132-
reason: 'Unthread Ticket',
133-
});
130+
// Create thread based on channel type to satisfy TypeScript's type constraints
131+
if (interaction.channel.type === ChannelType.GuildAnnouncement) {
132+
thread = await interaction.channel.threads.create({
133+
name: `ticket-#${ticketObj.friendlyId}`,
134+
type: ChannelType.AnnouncementThread,
135+
reason: 'Unthread Ticket',
136+
});
137+
}
138+
else {
139+
thread = await interaction.channel.threads.create({
140+
name: `ticket-#${ticketObj.friendlyId}`,
141+
type: ChannelType.PrivateThread,
142+
reason: 'Unthread Ticket',
143+
});
144+
}
134145

135146
if (!thread) {
136147
throw new Error('Failed to create Discord thread');

0 commit comments

Comments
 (0)