Google表单和Discord Webhook问题

时间:2019-09-30 02:29:04

标签: javascript discord

当前使用通过以下脚本连接到Google表单的不和谐Webhook。
我的问题是在表格上,我希望人们提交照片或照片的imgur链接。
当他们这样做时,webhook会正确嵌入所有内容,但只显示指向照片的链接
而不是照片预览。反正我可以解决这个问题吗?

var POST_URL = "websocketurlhere";

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",
        "payload": JSON.stringify({
            "embeds": [{
                "title": "yourtitle",
                "fields": items,
                "footer": {
                    "text": "yourtext"
                }
            }]
        })
    };

    UrlFetchApp.fetch(POST_URL, options);
};

https://pastebin.com/bLNr5vKT

0 个答案:

没有答案