M
M
manro0262020-03-23 09:11:53
Google Apps Script
manro026, 2020-03-23 09:11:53

How to add an image to a message?

There was a need for a bot that sends applications from the form to discord. I found this script online:

var POST_URL = "https://discordapp.com/api/webhooks/691027432282652682/sBGo6V4Gt_D65wAZChE-sdHeWP5t777tE8Ip-o957o7Dkv2SqfHxKzAHm1Gt49RMS";

function onSubmit(e) {
    var form = FormApp.getActiveForm();
    var allResponses = form.getResponses();
    var latestResponse = allResponses[allResponses.length - 1];
    var response = latestResponse.getItemResponses();
    var items = [];

    for (var i = 0; i < response.length; i++) {
        var question = response[i].getItem().getTitle();
        var answer = response[i].getResponse();
        try {
            var parts = answer.match(/[\s\S]{1,1024}/g) || [];
        } catch (e) {
            var parts = answer;
        }

        if (answer == "") {
            continue;
        }
        for (var j = 0; j < parts.length; j++) {
            if (j == 0) {
                items.push({
                    "name": question,
                    "value": parts[j],
                    "inline": false
                });
            } else {
                items.push({
                    "name": question.concat(" (cont.)"),
                    "value": parts[j],
                    "inline": false
                });
            }
        }
    }

    var options = {
        "method": "post",
        "headers": {
            "Content-Type": "application/json",
        },
        "payload": JSON.stringify({
            "content": "‌", // This is not an empty string
            "embeds": [{
                "title": "Уведомление о перерыве.",
                "fields": items,
                "footer": {
                  "text": "Подпись: Отдел секретариата"
                }
            }]
        })
    };

    UrlFetchApp.fetch(POST_URL, options);
};

I'm not good at programming, so I'm writing here right away. Where and what should I add so that the posts still have a small picture, let's say somewhere to the right of the entire text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
userpro, 2020-08-12
@userpro

if it's about something that is just a picture and letters, then just insert the file (picture) and at the bottom there is text details or something like that and write what you wanted

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question