Skip to content

Send Discord message via webhook

  1. Create a Discord webhook
  2. Add the webhook to your Val Town environment variables
  3. Use @stevekrouse.discordWebhook to send the message

Untitled

You can browse example usages of this function here.

Example Integration

Untitled

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");
}