Created
March 14, 2022 19:30
-
-
Save mckelvey/3ec18c97b539cf98d5e488b84e6e3784 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// via: https://dev.to/kushalst/discord-notifications-on-google-form-submission-1837 | |
var POST_URL = "discord-webhook-url"; | |
function onSubmit(event) { | |
var discordPayload = { | |
content: "Form Submission", | |
embeds: [ | |
{ | |
type: "rich", | |
title: "Form Entry", | |
color: 307506, | |
fields: [] | |
} | |
] | |
}; | |
event.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" | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment