Created
April 12, 2017 07:59
-
-
Save jamietech/50163ab603a81953f29ba2819a9a18ff to your computer and use it in GitHub Desktop.
Sends Google form payload to Discord webhook
This file contains 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
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()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeError: Cannot read property "response" from undefined. (line 4, file "Code")
HELP
:(