type DiscordEmbedField = { name: string; value: string; inline?: boolean; }; type DiscordEmbed = { title?: string; description?: string; url?: string; color?: number; fields?: DiscordEmbedField[]; footer?: { text: string; }; }; type DiscordMessage = { content?: string; embeds?: DiscordEmbed[]; }; const DISCORD_TIMEOUT_MS = 10_000; export async function postToDiscord( webhookUrl: string, message: DiscordMessage, ): Promise { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), DISCORD_TIMEOUT_MS); try { const response = await fetch(webhookUrl, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(message), signal: controller.signal, }); if (!response.ok) { const errorText = await response.text(); throw new Error( `Discord webhook request failed (${response.status}): ${errorText}`, ); } } catch (error) { if (error instanceof Error && error.name === "AbortError") { throw new Error( `Discord webhook request timed out after ${DISCORD_TIMEOUT_MS}ms`, ); } throw error; } finally { clearTimeout(timeoutId); } }