不和谐的Webhook消息无法发送 [英] Discord Webhook Message cannnot send
问题描述
所以我有这段代码是某人不久前发布的.它已经完美地工作了一年.它采用google形式的答案,并将其作为webhook发布到不和谐频道.从昨天开始,它不再起作用了.脚本没有任何改变.
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:
对 https://discordapp.com 的请求失败,返回了代码400.服务器响应被截断:{"message":无法发送空消息",代码":50006}(使用MutantHttpExceptions选项检查完整响应)在onSubmit(代码:54)
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)
任何人都可以给我的帮助都会很棒.我尝试联系不和谐的支持人员,但他们不会帮忙,因为它的API/开发版本
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 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",
这篇关于不和谐的Webhook消息无法发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!