Discord Webhook Message cannnot send

感情迁移 提交于 2020-01-06 02:32:09

问题


So I have this code that someone had posted from awhile back. It has been working flawlessly for a year now. It takes the google form answers and posts them to discord channel as a webhook. Now since yesterday, it is not working anymore. Nothing has changed with the script.

function onSubmit(e) {
    var form = FormApp.getActiveForm();
    var POST_URL = "****";
    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({
          "content":"Hello, World!",

           "embeds":[{
                "title":"War Times Form",
                "fields":items,
                "footer":{
                    "text":"***Please verify these are Correct***"
                }
            }] 
        })
                                 };
Logger.log("[METHOD] onFormSubmit");
  Logger.log(items);
  Logger.log(options);
  var response = UrlFetchApp.fetch(POST_URL, options);
  Logger.log(response);
};

This is what logging is saying its submitting

[19-11-24 10:13:28:400 PST] {method=POST, payload={"content":"Hello, World!","embeds":[{"title":"War Times Form","fields":[{"name":"Post your clan name:","value":"fds","inline":false},{"name":"Post your name","value":"fds","inline":false},{"name":"Clan that you are declaring against:","value":"dfsa","inline":false},{"name":"Days and times your group is available was HQ fight (must be in EST):","value":"sdaf","inline":false}],"footer":{"text":"***Please verify these are Correct***"}}]}}

However, I keep getting this error:

Request failed for https://discordapp.com returned code 400. Truncated server response: {"message": "Cannot send an empty message", "code": 50006} (use muteHttpExceptions option to examine full response) at onSubmit(Code:54)

Any help that anyone can give me would be great. I have tried contacting discord support and they wont help as its API/Dev


回答1:


So found the answer had to add to the options that get sent through the request. Discord apparently changed it and didn't tell anyone that you have to declare it

"contentType" : "application/json",



来源:https://stackoverflow.com/questions/59022027/discord-webhook-message-cannnot-send

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!