【发布时间】:2021-11-25 06:05:47
【问题描述】:
我正在尝试触发 Discord webhook 这样做:
if ('1' !== '2') {
console.log(`This is false!`)
sendMessage();
我要发送的消息是:
function sendMessage() {
var request = new XMLHttpRequest();
request.open("POST", "https://discord.com/api/webhooks/XYZ");
request.setRequestHeader('Content-type', 'application/json');
var myEmbed = {
title: "Test",
color: 0xFF7100,
fields: [
{
name: 'Test',
value: 'Test',
}, {
name: 'Test 2',
value: "Test 2",
}],
timestamp: new Date(),
footer: {
text: 'v 1.6.2'
}
}
var params = {
username: "Test Webhook",
avatar_url: "",
color: "#FF7100",
content: "",
embeds: [myEmbed],
}
request.send(JSON.stringify(params));
}
我已经在浏览器控制台中尝试了 sendMessage(),它成功发送了 webhook,表明我的项目中没有触发 sendMessage(),但是 console.log 可以工作。
谁能解释我在哪里出错了?
【问题讨论】:
标签: typescript discord xmlhttprequest webhooks