最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord Webhook Message cannnot send - Stack Overflow

programmeradmin0浏览0评论

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 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

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. 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

Share Improve this question edited Nov 24, 2019 at 20:39 abdullahalali 4062 gold badges6 silver badges18 bronze badges asked Nov 24, 2019 at 20:23 RocketMyrrRocketMyrr 791 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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",

发布评论

评论列表(0)

  1. 暂无评论