Skip to content

Instantly share code, notes, and snippets.

@Gjum
Forked from jamietech/Discord-webhook.gs
Last active May 31, 2022 14:41
Show Gist options
  • Save Gjum/a5ea41700d041fcc297fe19291288f95 to your computer and use it in GitHub Desktop.
Save Gjum/a5ea41700d041fcc297fe19291288f95 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": JSON.stringify(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: false,
};
Logger.log("Attempting to send:");
Logger.log(JSON.stringify(data));
var response = UrlFetchApp.fetch("DISCORDWEBHOOK", options);
Logger.log(response.getContentText());
};
@Shindy117
Copy link

Shindy117 commented Jul 7, 2018

Hi there me and my friends are using this code. And we have run into a issue. its the "for loop" the e.response.getItemResponses" isn't working if I comment that code out it still posts to the discord server. So the web hook and our mentions work but it isn't grabbing the responses. When I uncomment the for loop and fill out the form it doesn't work. YES I filled out my triggers. e.response isn't getting referenced or read by the code. We are using a google form and the script attached is suppose to grab the responses. but the for loop bugs out when it reads the e.response line in the for loop.

if you'd like I can post the script but its the exact one you have. Line 4 doesn't want to work.

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