Skip to content

Instantly share code, notes, and snippets.

@Rinlama
Created July 2, 2022 18:53
Show Gist options
  • Select an option

  • Save Rinlama/2722926068867b8c2838428a83fe596f to your computer and use it in GitHub Desktop.

Select an option

Save Rinlama/2722926068867b8c2838428a83fe596f to your computer and use it in GitHub Desktop.
Google Apps Script Integration With Discord
function Submit() {
// add your discord Webhook Endpoint
const webhooks = "";
const form = FormApp.getActiveForm();
const allResponses = form.getResponses();
const latestResponse = allResponses[allResponses.length - 1];
const response = latestResponse.getItemResponses();
const email = latestResponse.getRespondentEmail();
let content = "";
for (var i = 0; i < response.length; i++) {
const question = response[i].getItem().getTitle();
const answer = response[i].getResponse();
content += `${question}\n${answer}\n`;
}
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
muteHttpExceptions: false,
payload: JSON.stringify({
content: `${email} responded survey`,
embeds: [
{
title: form.getTitle(),
description: content,
timestamp: new Date().toISOString(),
},
],
}),
};
try {
UrlFetchApp.fetch(webhooks, options);
} catch (error) {
console.log(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment