How to send an HTML form to Discord

Discord channels have webhooks: a secret URL that posts a message to one channel when you send it JSON. That makes Discord an easy place to collect form submissions for a small team, a community or a side project. The form just can’t call the webhook itself.

This guide covers the webhook, a small Cloudflare Worker that sits between your form and Discord, the two Discord-specific traps, and a form backend that does it for you.

1. Create a Discord webhook

  1. Open your server’s Server Settings → Integrations → Webhooks.
  2. Create a webhook, name it (“Website forms”) and pick the channel.
  3. Click Copy Webhook URL. It looks like https://discord.com/api/webhooks/123…/abc….

Anyone with that URL can post to your channel, so it never goes in your page source.

2. Option A: a Cloudflare Worker

The form posts to your Worker:

<form action="https://contact-to-discord.YOUR-SUBDOMAIN.workers.dev" method="POST">
<input name="name" placeholder="Name" required>
<input name="email" type="email" placeholder="Email" required>
<textarea name="message" placeholder="Message" required></textarea>
<!-- Honeypot: hidden from people, bots fill it in -->
<div aria-hidden="true" style="position:absolute; left:-9999px">
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Send</button>
</form>

The Worker turns the fields into a Discord message:

export default {
async fetch(request, env) {
if (request.method !== "POST") return new Response("Method not allowed", { status: 405 });
const form = await request.formData();
if (form.get("_gotcha")) return Response.redirect(env.THANKS_URL, 303);
const name = String(form.get("name") ?? "").slice(0, 200);
const email = String(form.get("email") ?? "").slice(0, 200);
const message = String(form.get("message") ?? "").slice(0, 1500);
if (!email || !message) return new Response("Email and message are required", { status: 400 });
const res = await fetch(env.DISCORD_WEBHOOK_URL, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
content: `**New message from ${name}** (${email})\n${message}`,
// Never let visitor text ping @everyone, @here, roles or users.
allowed_mentions: { parse: [] },
}),
});
if (!res.ok) return new Response("Couldn't send your message. Please try again.", { status: 502 });
return Response.redirect(env.THANKS_URL, 303);
},
};

Store the URL as a secret and deploy:

Terminal window
npx wrangler secret put DISCORD_WEBHOOK_URL
npx wrangler deploy

with THANKS_URL set as a variable in wrangler.jsonc.

The two Discord traps

  • Mentions. Discord turns @everyone and @here in a webhook message into real pings. Without allowed_mentions: { parse: [] }, any visitor can notify your whole server. That one line turns every mention off.
  • Length. A message’s content is capped at 2,000 characters, and Discord rejects longer ones with a 400. Trim the message (the code keeps 1,500 for the text, leaving room for the name and email), or the long submissions are the ones you lose.

What this version doesn’t do

  • Spam. Bots that post straight to the Worker, and hand-written SEO pitches, still reach the channel. See how to stop contact form spam for the layers.
  • Storage. If the webhook is deleted or Discord is down, the submission is gone.
  • Rate limits. One script can flood the channel.
  • Sorting. Every message lands in the same channel.

3. Option B: a form backend

With Formkove, the form posts to a Formkove URL instead of your own Worker:

<form action="https://app.formkove.com/api/forms/YOUR_FORM_ID/submissions" method="POST">

Then, in the form’s Integrations → Discord, paste the webhook URL from step 1 and click Send test. Each submission arrives as a message with the form name, the fields and, when AI is on, its sentiment and tags.

To send only some submissions to a channel, add a routing rule to the connection. For example, a #leads channel that only gets submissions tagged sales-lead, or a #bugs channel for submissions where the topic field is bug. Rules can test the tags and sentiment Formkove adds, the spam score, or any form field, and you can add one Discord connection per channel.

What comes with it:

  • Spam held back before anything reaches Discord, kept in your dashboard for 30 days in case one was a real message.
  • Every submission saved and emailed to you, even when Discord is down. Failed deliveries are retried and listed in Delivery history.
  • Rate limits on every form, and mentions in submissions never ping your server.

Discord, tags and routing are on the Pro and Agency plans (pricing). Setup details are in the Discord docs.

← All posts