Skip to content

Instantly share code, notes, and snippets.

@jamietech
Created April 12, 2017 07:59
Show Gist options
  • Save jamietech/50163ab603a81953f29ba2819a9a18ff to your computer and use it in GitHub Desktop.
Save jamietech/50163ab603a81953f29ba2819a9a18ff to your computer and use it in GitHub Desktop.
Sends Google form payload to Discord webhook
function onFormSubmit(e) {
var fields = [];
for (i = 0; i < e.response.getItemResponses().length; i++) {
var response = e.response.getItemResponses()[i];
fields.push({
"name": response.getItem().getTitle(),
"value": response.getResponse(),
"inline": false
});
}
var data = {
"embeds": [{
"title": "**New form submission** — " + (e.source.getTitle() != null && e.source.getTitle().length > 0 ? e.source.getTitle() : "Untitled Form"),
"type": "rich",
"fields": fields
}]
};
var options = {
method: "post",
payload: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
muteHttpExceptions: true
};
Logger.log("Attempting to send:");
Logger.log(JSON.stringify(data));
var response = UrlFetchApp.fetch("DISCORDWEBHOOKURL", options);
Logger.log(response.getContentText());
};
@svaltqt
Copy link

svaltqt commented Nov 9, 2017

TypeError: Cannot read property "response" from undefined. (line 4, file "Code")
HELP

:(

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