R
R
Rezui2021-08-29 20:59:17
API
Rezui, 2021-08-29 20:59:17

How to add an image to the webhook using this script?

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);
};


What would look like this
612bca2c9baab818742673.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-29
@Rezui

{
    ...
    "embeds": [{
        ...
        "thumbnail": {
            "url": "url_изображения"
        }
    }]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question