DEV Community

loading...
Cover image for Discord notifications on Google form submission

Discord notifications on Google form submission

kushalst profile image Kushal S T ・1 min read

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

Discussion (0)

Forem Open with the Forem app