Skip to content

Instantly share code, notes, and snippets.

@Antouto
Last active October 20, 2024 07:51
Show Gist options
  • Save Antouto/8ab83d83482af7c516f0b2b42eaee940 to your computer and use it in GitHub Desktop.
Save Antouto/8ab83d83482af7c516f0b2b42eaee940 to your computer and use it in GitHub Desktop.
Create custom forms for your discord server and send submissions to a channel of your choice using webhooks

To create a form use the (Form builder)(https://create.discordforms.app/), you are not required to understand json.

Links:

Creating a form

To set up this bot manually you are required to understand JSON and how to create a json file. Learn More If you do not you can use this site to help you: https://create.discordforms.app/

The /form create command sends a message that has buttons which when clicked by the user open different forms. You will provide your configuration for the forms and the message in the json parameter of the command as a json file attachement. You can create a blank text file, paste in the json and change the files ending to .json or you can create a json file in vscode. Whatever works for you.

JSON Structure
Field Type Description
message? message object The message the forms are attached to. Don't include if you'd like to use a slash command to open your form
forms array of form objects The forms that are added to the message
select_menu_placeholder? string Max 100 chars. Placeholder for the select menu to open forms. Don't include if you'd like to use buttons or a slash command to open forms.
application_command? application_command object Defines a slash command which is used to open the form. Don't include type and options keys. Don't include this key at all if you'd like to open your forms using buttons or a select menu.
Example JSON:

If you try to use this make sure to put in your own submit_channel_id fields.

{
   "message": {
     "content": "Forms:"
   },
  "forms": [
    {
      "submit_channel_id": "999776512465186907",
      "button": {
        "label": "Submit Feedback",
        "style": 1
      },
      "modal": {
        "title": "Submit Feedback",
        "components": [
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Title / Summary",
                "max_length": 256,
                "style": 1
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Description (Optional)",
                "style": 2,
                "required": false
              }
            ]
          }
        ]
      }
    },
    {
      "submit_channel_id": "999776512465186907",
      "button": {
        "label": "Report User",
        "style": 4
      },
      "modal": {
        "title": "Report User",
        "components": [
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Username",
                "placeholder": "spammer",
                "max_length": 256,
                "style": 1
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Evidence",
                "style": 2
              }
            ]
          }
        ]
      }
    }
  ]
}
Form Structure
Field Type Description
submit_channel_id? * string The discord channel form submissions will be posted to
webhook_url? * string Premium Feature. The discord webhook url form submissions will be posted to
submit_channel_id? * string The channel form submissions will be posted to (must be in the same server as the form is in)
external_webhook_url? * string The non-discord webhook url form submissions will be posted to
external_submission_structure? JSON The data structure for the `external_wehhook_url`. Supports variables.
button? ** button object The button that opens your form
select_menu_option? ** select menu option object The select menu option that opens your form
pages array of page objects The forms pages
submit_message? message object Custom Submission Message. Read More
conformation_message? message object Custom Ephemeral Conformation Message. Read More
cooldown? integer Premium Feature. Cooldown in seconds. 0 for infinity.
role_restriction? role_restriction object White- or Blacklist roles from using the form
on_submit? on_submit object Additional Actions to perform on form submission

* You need to include at least one of submit_channel_id, webhook_url, and external_webhook_url. You could for example use an external_webhook_url to send form responses to google sheets. Here is a google sheets addon that creates a webhook for you: https://workspace.google.com/marketplace/app/webhooks_for_sheets/860288437469.

** You need to include either button or select_menu_option in all of the forms depening on if you want your forms to be opened by buttons or select menus.

Button Structure
Field Type Description
label? string text that appears on the button, max 80 characters
style integer one of button styles
emoji? partial emoji name, id, and animated
Button Styles
Button Value
Primary 1
Secondary 2
Success 3
Danger 4
Select Menu Option Structure
Field Type Description
label string text that appears on the option, max 100 characters
description? string an additional description of the option, max 100 characters
emoji? partial emoji name, id, and animated
Page Structure
Field Type Description
modal modal object The form pop-up modal
Modal Structure
Field Type Description
title string the title of the pop-up modal, max 45 characters
components array of action rows between 1 and 5 (inclusive) action rows that make up the modal
Action Row Structure
Field Type Description
type component type 1 for an action row
components array of text inputs exactly 1 text field
Text Input Structure
Field Type Description
type component type 4 for a text input
style integer 1 for single, 2 for multi-line input
label string the label for this component, min 1, max 45
min_length? integer the minimum input length for a text input, min 0, max 1024
max_length? integer the maximum input length for a text input, min 1, max 1024
required? boolean whether this component is required to be filled, default true
value? string a pre-filled value for this component, max 1024 characters
placeholder? string custom placeholder text if the input is empty, max 100 characters
Role Restriction Structure
Field Type Description
type string whitelist or blacklist
roles array of snowflakes Array of the ids of the roles you want to resctrict
message? message object Custom message when user tries to open restricted form. Supports variables.
On Submit Structure
Field Type Description
ADD_ROLE_TO_SUBMITTER? snowflake Adds a specified role to the form submitter
REMOVE_ROLE_FROM_SUBMITTER? snowflake Removes a specified role from the form submitter

? suffix means "optional field"

Webhooks

Submit Messages

The default submission messages look like this:

To customise this message you can add a submit_message in a form object where you want to customise the submission. This submit_message is a discord message object and you can use variables in it. To separately customise the direct message and guild submission message use dm_submit_message and guild_submit_message instead. You can set dm_submit_message to null to remove the dm submission message message completely.

You can also use conformation_message if you prefer a ephemeral reply to the form submission. ("flags": 1 << 6 is set by default) Note that using this will disable the default dm submission message, which you can re-enable using dm_submit_message if you wish.

Example form with custom submit messages:

{
   "message": {
     "content": "Advertise your clan:"
   },
  "forms": [
    {
      "submit_channel_id": "INSERT_YOUR_SUBMIT_CHANNEL_ID",
      "button": {
        "label": "Advertise Clan",
        "style": 1
      },
      "submit_message": {
        "embeds": [
          {
            "color": "{UserAccentColour}",
            "title": "{TextInputValue1}",
            "description": "{TextInputValue2}",
            "fields": [
              {
                "name": "{TextInputLabel3}",
                "value": "{TextInputValue3}"
              }
            ],
            "thumbnail": {
              "url": "{TextInputValue5}"
            },
            "image": {
              "url": "{TextInputValue4}"
            },
            "footer": {
              "icon_url": "{MemberAvatarURL}",
              "text": "{NicknameAndUserTag} - ID: {UserID}"
            }
          }
        ]
      },
      "modal": {
        "title": "Post Clan Advertisement",
        "components": [
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Clan Name",
                "style": 1,
                "max_length": "256"
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Clan Description",
                "style": 2
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Clan Invite Link",
                "style": 1,
                "placeholder": "https://discord.gg/...",
                "min_length": "20",
                "max_length": "100"
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Banner URL",
                "style": 1,
                "placeholder": "https://...",
                "min_length": "12",
                "required": false
              }
            ]
          },
          {
            "type": 1,
            "components": [
              {
                "type": 4,
                "label": "Icon/Logo URL",
                "style": 1,
                "placeholder": "https://...",
                "min_length": "12",
                "required": false
              }
            ]
          }
        ]
      }
    }
  ]
}

Example Submission:

Variables

User variables refer to the form submitter. To refer to the person who used a button use {InteractionUserName}, {InteractionUserMention} and {InteractionUserID}.
Variable Example Fallback
{TextInputLabel<1-5>} How are you? null
{TextInputValue<1-5>} Great! null
{UserName} Forms
{UserDisplayName} Forms Username
{UserDiscriminator}* 5609 0
{UserID} 942858850850205717
{UserTag}* Forms#5609 Username
{UserMention} <@942858850850205717>
{UserAccentColour} 5793266 Blurple (5793266)
{UserAvatarURL} cdn.discord.com/avatars...
{UserProfileURL} discord.com/users...
{MemberNickname} Form Bot Username
{MemberAvatarURL} cdn.discord.com/avatars... User Avatar
{NicknameAndUsername} Form Bot (Forms) Just Username
{UsernameAndNickname} Forms (Form Bot) Just Username
{NicknameAndUserTag}* Form Bot (Forms#5609) Just User Tag or Just Username
{UserTagAndNickname}* Forms#5609 (Form Bot) Just User Tag or Just Username
{FormTitle} Staff Application
{UnixTimestamp}** 1710619508
{RandomUUID}*** d83a755e-781c-43cf-b24a-a18d1f390334
{ApplicationID} 942858850850205717
{ChannelName} ticket

* Deprecated

** The unix timestamp is in seconds and can be displayed in a message using <t:{UnixTimestamp}>. Optionally there are also different timestamp styles.

*** Uses javascripts crypto.randomUUID() function: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID

@Antouto
Copy link
Author

Antouto commented Dec 12, 2022

The invite for the support server is currently invalid.

Thanks @vico93, fixed.

@TheTrueInfinity
Copy link

The template given on https://form-builder.pages.dev/templates is not working.

@g336
Copy link

g336 commented Jun 17, 2023

I am getting a problem, is there any solution to this?
error

@WernerBrownJr
Copy link

Greetings

I need to use more than 25 forms, is there a way past that limit or is this an obstacle I can not overcome?

Regards.

@AkaLuiz
Copy link

AkaLuiz commented Oct 3, 2024

There is a way to create a form that has a button to send images?
Also, there is a way to create a form by selecting a message? For example, if I want to make a denounce of a message, so I want to take the message id, user id and take a picture of that message, is this possible with your bot?

@Antouto
Copy link
Author

Antouto commented Oct 3, 2024

@AkaLuiz It's not possible to upload images in forms, but if your users upload their images elsewhere they could put the link into the form

About your second question, I'm not completely sure what you mean, but here is an example of a form that can be submitted by right-clicking a message. (Premium feature) This example is a message report form.
Screenshot 2024-10-03 at 19 27 05
Screenshot 2024-10-03 at 19 27 36
Screenshot 2024-10-03 at 19 27 53

@bugboy1769
Copy link

Hi, I am currently using the forms as a means to exchange reports on a day to day basis on a project me and one more person are collaborating on. It allows us to record what we did on the day. I want to know if there is a way to send the form data to an external source where it can be collated for record keeping purposes?

@Antouto
Copy link
Author

Antouto commented Oct 5, 2024

@bugboy1769 Yes, that is possible with the external_webhook_url parameter on the form object which allows you to send the data to any URL you want.

If you want to send responses to google sheets for example then you can do so by installing this google sheets plugin:
https://workspace.google.com/marketplace/app/webhooks_for_sheets/860288437469

and take the webhook url that it gives you and put it into your JSON file by adding this to the form object:

"external_webhook_url": "INSERT_YOUR_GOOGLE_SHEETS_WEBHOOK_URL"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment