Send a message to a Discord channel. It's useful for notifying your team or community when someone interesting happens, like a user signup, Stripe payment, mention on social media, etc.
Follow the instructions here. It only takes a minute.
Paste the webhook URL into your val's environment variables as
DISCORD_WEBHOOK_URL.
import { discordWebhook } from "https://esm.town/v/std/discordWebhook/main.ts";
await discordWebhook({ content: "Hi from val town!" });
Any text, rendered as markdown. If over 2000 characters, we will truncate it to the first 2000 for you.
You can pass the webhook url as a parameter explicitly. Otherwise, this helper
function will implicitly look in your env variables under DISCORD_WEBHOOK_URL.
ie "SUPPRESS_EMBEDS".
Learn more about flag options here.
When true (the default), adds an "Edit Val" button to your Discord message
that links back to the val top-level val as set via the
VALTOWN_ENTRYPOINT env var.
Set to false to disable this button.
// With the Edit Val button (default)
await discordWebhook({ content: "Check this out!" });
// Without the Edit Val button
await discordWebhook({ content: "Check this out!", editValButton: false });
This helper function only supports content and flags as parameters. There
are
other parameters that Discord supports.
PRs welcome!