Discord Webhook 的 Google 表单不起作用

问题描述 投票:0回答:1

几年前我从 Github 上提取了这段代码,该代码应该提取 Google 表单响应并使用 Webhook 将其发布到 Discord 频道。直到几个月前它都运行得很好。代码如下:

const POST_URL = "https://discord.com/api/webhooks/1237046117418401842/WFieSt7WaMHYWxmf58U6Cvui3t2LWGV1sZffw-XhCG9d5v5PB39ot7FGLvhKu5KO4VMB";

function onSubmit(e) {
    const response = e.response.getItemResponses();
    let items = [];

    for (const responseAnswer of response) {
        const question = responseAnswer.getItem().getTitle();
        const answer = responseAnswer.getResponse();
        let parts = []

        try {
            parts = answer.match(/[\s\S]{1,1024}/g) || [];
        } catch (e) {
            parts = answer;
        }

        if (!answer) {
            continue;
        }

        for (const [index, part] of Object.entries(parts)) {
            if (index == 0) {
                items.push({
                    "name": question,
                    "value": part,
                    "inline": false
                });
            } else {
                items.push({
                    "name": question.concat(" (cont.)"),
                    "value": part,
                    "inline": false
                });
            }
        }
    }

    const options = {
        "method": "post",
        "headers": {
            "contentType": "application/json",
        },
        "payload": JSON.stringify({
            "content": "‌",
            "embeds": [{
                "title": "GotFA Application",
                "color": 33023, // This is optional, you can look for decimal colour codes at https://www.webtoolkitonline.com/hexadecimal-decimal-color-converter.html
                "fields": items,
                "footer": {
                    "text": "Some footer here"
                },
                "timestamp": new Date().toISOString()
            }]
        })
    };

    UrlFetchApp.fetch(POST_URL, options);
};

提交 Google 表单后,它不会发布到 Discord webhook - 相反,我收到此错误:

Exception: Request failed for https://discord.com returned code 400. Truncated server response: `{"message": "Cannot send an empty message", "code": 50006}
discord webhooks
1个回答
0
投票

我很确定发生错误的原因是因为您发送了一条空消息。这意味着这行:

"content":""

您必须在该内容中添加一些内容,否则它将无法工作。或者,只需删除应该起作用的内容值即可。

© www.soinside.com 2019 - 2024. All rights reserved.