Send Discord message via webhook
- Create a Discord webhook
- Add the webhook to your Val Town environment variables
- Use
@stevekrouse.discordWebhook
to send the message
You can browse example usages of this function here.
Example Integration
import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook?v=3";import process from "node:process";
// # New Val Town User (on Clerk) -> Val Town Discord notification// Translates one kind of webhook (Clerk) into another (Discord)export async function handleDiscordNewUser(req: Request) { // check custom auth secret sent from clerk if (req.headers.get("auth") !== process.env.clerkNonSensitive) return new Response("Unauthorized", { status: 401 }); const body = await req.json(); await discordWebhook({ url: process.env.newUserDiscord, content: body.data.email_addresses[0].email_address + " " + body.data.profile_image_url, }); return new Response("Success");}