Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onFormSubmit(e) {
- var form = FormApp.getActiveForm();
- var formResponses = form.getResponses();
- //look at the newest one only
- var latestResponse = formResponses[formResponses.length-1].getItemResponses();
- var messageContent = "";
- //Instead of printing the full question, send a shorter replacement of the question. For example, alias("What is your age","Age"); would make the Discord message send "Age" instead of writing out the full question, "What is your name?"
- function alias(q,replacement) {
- if(question == q){
- question = replacement;
- }
- }
- for (var i = 0; i < latestResponse.length; i++) {
- var question = latestResponse[i].getItem().getTitle(), response = latestResponse[i].getResponse();
- if(response) {
- //Alias example
- //alias("What is your age","Name");
- messageContent += "**"+question+":** ";
- messageContent += response+"\n";
- }
- }
- Logger.log(messageContent);
- //Send a fancy embed
- var messagePayload = {
- "content": "",
- "embeds": [{
- "title": "Form Response",
- "description": messageContent,
- "color": 2031480,
- "footer": {
- "icon_url": "http://is2.mzstatic.com/image/thumb/Purple128/v4/b1/9b/6c/b19b6c17-4e81-d800-3d1e-c0935f5ec5ba/source/300x300bb.jpg",
- "text": "Footer Text"
- },
- "thumbnail": {
- "url": "http://is2.mzstatic.com/image/thumb/Purple128/v4/b1/9b/6c/b19b6c17-4e81-d800-3d1e-c0935f5ec5ba/source/300x300bb.jpg"
- },
- "fields": [
- ]
- }]
- };
- var APIConfig = {
- "method": "POST",
- "headers": {
- "Content-Type": "application/json"
- },
- "payload": JSON.stringify(messagePayload)
- };
- var response = UrlFetchApp.fetch("https://discordapp.com/api/webhooks/INSERT_WEBHOOK_URL_HERE", APIConfig);
- var json = response.getContentText();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement