Created
July 2, 2022 18:53
-
-
Save Rinlama/2722926068867b8c2838428a83fe596f to your computer and use it in GitHub Desktop.
Google Apps Script Integration With Discord
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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