Skip to content

Instantly share code, notes, and snippets.

@dieter007
Created January 21, 2019 18:11
Show Gist options
  • Select an option

  • Save dieter007/a1ceab5bc527b72907b809e4234221a5 to your computer and use it in GitHub Desktop.

Select an option

Save dieter007/a1ceab5bc527b72907b809e4234221a5 to your computer and use it in GitHub Desktop.
Webhook for Google Forms to post submissions to a Discord channel
var POST_URL = "WEBHOOKURL";
function onSubmit(e) {
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var response = latestResponse.getItemResponses();
var items = [];
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle();
var answer = response[i].getResponse();
var parts = answer.match(/[\s\S]{1,1024}/g) || [];
if (answer == "") {
continue;
}
for (var j = 0; j < parts.length; j++) {
if (j == 0) {
items.push({
"name": question,
"value": parts[j],
"inline": false
});
} else {
items.push({
"name": question.concat(" (cont.)"),
"value": parts[j],
"inline": false
});
}
}
}
var options = {
"method": "post",
"payload": JSON.stringify({
"embeds": [{
"title": "TOP TEXT CHANGE THIS IN SCRIPT",
"fields": items,
"footer": {
"text": "BOTTOM TEXT CHANGE THIS IN SCRIPT"
}
}]
})
};
UrlFetchApp.fetch(POST_URL, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment