Skip to content

Instantly share code, notes, and snippets.

@danferns
Created February 11, 2022 06:16
Show Gist options
  • Select an option

  • Save danferns/b51e564f33cb8011fd4132542b856430 to your computer and use it in GitHub Desktop.

Select an option

Save danferns/b51e564f33cb8011fd4132542b856430 to your computer and use it in GitHub Desktop.
Google Apps Script to forward form responses straight into your Discord server
const POST_URL = "INSERT DISCORD WEBHOOK URL HERE";
// aliases allow you to use alternative titles in the webhook
// for example, in the form the title may be "Your Name"
// you can change it to just "Name" in the webhook by setting an alias for that field.
// you will need to find the field's ID (the numbers) for that
const ALIASES = {
123456789: "Email Address",
789102112: "Name",
151617181: "Browser Version" // replaces "Which browser are you using <my app> on?"
}
function onSubmit() {
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var response = latestResponse.getItemResponses();
var payload = {
embeds: [
{
fields: []
}
]
};
for (const field of response) {
const name = ALIASES[field.getItem().getId()] || field.getItem().getTitle();
const value = field.getResponse();
if ([name, value].includes("")) continue;
payload.embeds[0].fields.push({name: name, value: String(value)})
}
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
UrlFetchApp.fetch(POST_URL, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment