Skip to content

Instantly share code, notes, and snippets.

@mathislajs
Created August 21, 2024 00:38
Show Gist options
  • Save mathislajs/9d70c37b161deb1355beb7af2027ba74 to your computer and use it in GitHub Desktop.
Save mathislajs/9d70c37b161deb1355beb7af2027ba74 to your computer and use it in GitHub Desktop.
googleforms-discordwebhook
function onFormSubmit(e) {
const webhookUrl = 'YOUR_DISCORD_WEBHOOK_URL'; // Replace with your Discord webhook URL
const formResponses = e.values;
const embed = {
title: "New Form Submission",
fields: [],
color: 7506394,
};
// Add form responses to embed fields
for (let i = 0; i < formResponses.length; i++) {
embed.fields.push({
name: `Question ${i + 1}`,
value: formResponses[i],
inline: false,
});
}
const payload = JSON.stringify({ embeds: [embed] });
const options = {
method: 'post',
contentType: 'application/json',
payload: payload,
};
UrlFetchApp.fetch(webhookUrl, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment