DEV Community

Cover image for Discord notifications on Google form submission
Kushal S T
Kushal S T

Posted on

4 1

Discord notifications on Google form submission

Step #1

Get discord webhook. https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks will help you understand how to get a webhook for your channel in Discord.

Step #2

Go to the Google form with which you want to integrate Discord. Click on the 3 dot menu on the top right and then click on Script EditorScreenshot 2021-04-03 at 8.14.42 PM

Step #3

Code...

var POST_URL = "YOUR_DISCORD_WEBHOOK_HERE";

  function onSubmit(e) {
  var discordPayload = {
    content: "New Form Submitted",
    embeds: [
      {
        type: "rich",
        title: "Form Entry",
        color: 307506,
        fields: []
      }
    ]
  };

  e.response.getItemResponses().forEach(function (i) {
    var v = i.getResponse() || "None";

    if (!Array.isArray(v))
      discordPayload.embeds[0].fields.push({
        name: i.getItem().getTitle(),
        value: v
      });
    else
      discordPayload.embeds[0].fields.push({
        name: i.getItem().getTitle(),
        value: v.toString()
      });
  });

  UrlFetchApp.fetch(POST_URL, {
    method: "post",
    payload: JSON.stringify(discordPayload),
    contentType: "application/json"
  });
}

Enter fullscreen mode Exit fullscreen mode

Step #4

Click on Edit -> Current project's triggers in Script Editor.
Screenshot 2021-04-03 at 8.19.01 PM

Step #5

Create a new trigger for onSubmit event
Screenshot 2021-04-03 at 8.23.25 PM

Step #6

There is no step 6! Go ahead and submit the form and test it. you'll see something like this in your Discord channel đź‘ľ đź‘ľ đź‘ľ
Screenshot 2021-04-03 at 8.37.59 PM

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (4)

Collapse
 
theindianappguy profile image
Sanskar Tiwari •

For people who do not want to code use
workspace.google.com/marketplace/a...

Collapse
 
samy_abdous_6f2af81becffe profile image
Samy Abdous •

Do you know how to assign each section to a webhooks please?

Collapse
 
depictukinetic profile image
Jaz •

I'd like this information too!

Collapse
 
wolffivem profile image
Wolf-FiveM •

it says this

6:24:19 PM Error TypeError: Cannot read property 'response' of undefined
onSubmit @ Code.gs:16

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay