javascript - Discord Webhook 消息无法发送
问题描述
所以我有这段代码,有人不久前发布的。它已经完美运行了一年。它采用 google 形式的答案并将它们作为 webhook 发布到不和谐频道。现在从昨天开始,它不再工作了。脚本没有任何改变。
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);
};
这就是记录在说它的提交
[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***"}}]}}
但是,我不断收到此错误:
https://discordapp.com的请求失败,返回代码 400。截断的服务器响应:{“消息”:“无法发送空消息”,“代码”:50006}(使用 muteHttpExceptions 选项检查完整响应)在 onSubmit(代码:54)
任何人都可以给我的任何帮助都会很棒。我曾尝试联系不和谐支持,但他们不会作为其 API/Dev 提供帮助
解决方案
所以发现答案必须添加到通过请求发送的选项中。Discord 显然改变了它并且没有告诉任何人你必须声明它
"contentType" : "application/json",
推荐阅读
- python - 我的堆叠条形图不断变得不可见
- azure - 尽管值为真,但阶段条件未评估为真
- reactjs - 提交输入时的路由
- java - 使用 OTEL Java 代理,如何在不使用 @WithSpan 的情况下创建新的上下文
- javascript - WebPack 错误:您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件
- angular - 如何使用参数和定义的路由进行嵌套路由?
- python - 机场问题,使用 DP(python)在 O(n^3) 中的矩阵中获得最大面积
- python - 在 Python 中为 GA API 迭代日期范围
- jquery - 使用不对应的 href 属性突出显示滚动上的当前链接
- go - 读取:对等方重置连接