Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/commands/report.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApplicationCommandType } from "discord-api-types/v10";
import {
ContextMenuCommandBuilder,
MessageFlags,
PermissionFlagsBits,
type MessageContextMenuCommandInteraction,
} from "discord.js";
Expand All @@ -16,6 +17,9 @@ const command = new ContextMenuCommandBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.SendMessages);

const handler = async (interaction: MessageContextMenuCommandInteraction) => {
// Defer immediately to avoid 3-second timeout - creating threads can take time
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });

await trackPerformance(
"reportCommand",
async () => {
Expand Down Expand Up @@ -50,8 +54,7 @@ const handler = async (interaction: MessageContextMenuCommandInteraction) => {
// Track command success
commandStats.commandExecuted(interaction, "report", true);

await interaction.reply({
ephemeral: true,
await interaction.editReply({
content: "This message has been reported anonymously",
});
} catch (error) {
Expand All @@ -69,8 +72,7 @@ const handler = async (interaction: MessageContextMenuCommandInteraction) => {
// Track command failure in business analytics
commandStats.commandFailed(interaction, "report", err.message);

await interaction.reply({
ephemeral: true,
await interaction.editReply({
content: "Failed to submit report. Please try again later.",
});
}
Expand Down
12 changes: 8 additions & 4 deletions app/commands/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ButtonStyle,
ContextMenuCommandBuilder,
InteractionType,
MessageFlags,
PermissionFlagsBits,
} from "discord.js";
import { Effect } from "effect";
Expand Down Expand Up @@ -33,6 +34,11 @@ export const Command = [
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
handler: (interaction) =>
Effect.gen(function* () {
// Defer immediately to avoid 3-second timeout - creating threads can take time
yield* Effect.tryPromise(() =>
interaction.deferReply({ flags: [MessageFlags.Ephemeral] }),
);

const { targetMessage: message, user } = interaction;

if (interaction.guildId) {
Expand All @@ -52,9 +58,8 @@ export const Command = [
);

yield* Effect.tryPromise(() =>
interaction.reply({
interaction.editReply({
content: `Tracked <#${thread.id}>`,
ephemeral: true,
components: reportId
? [
new ActionRowBuilder<ButtonBuilder>().addComponents(
Expand All @@ -74,9 +79,8 @@ export const Command = [
error,
});
yield* Effect.tryPromise(() =>
interaction.reply({
interaction.editReply({
content: "Failed to track message",
ephemeral: true,
}),
).pipe(Effect.catchAll(() => Effect.void));
}),
Expand Down