javascript - 如何获取表单数据并将其发送到 discord webhook?
问题描述
我正在构建一个小型仪表板,它将以 webhook 的形式将数据发送到不和谐。我能够从表单中检索数据,但不确定如何使用 node.js 和 discord.js 将其发送到 discord。这就是我现在所拥有的。我做了一些研究,发现请求是获取数据的方式,但不知道如何启动它。
form = document.getElementById("submit-form");
sucessMsg = document.getElementById("success");
function sucess(event) {
sucessMsg.style.display = "inline"
event.preventDefault()
console.log("form data:", getData())
}
function getData()
{
const formData = new FormData(form),
ret = {};
for(let [name, value] of formData.entries())
ret[name] = value;
return ret;
}
form.addEventListener("submit" , sucess )
解决方案
您需要 webhook id 和令牌,要获取这些信息,请转到 Server Settings>Integrations>Webhooks 并单击假装的 webhook 并复制 webhook URL。将 URL 粘贴到 google 上以查看 webhook 的 ID 和 Token。
const id = '';
const token = '';
const webhook = new Discord.WebhookClient(id, token);
webhook.send('Your message');
在此示例中,您不需要定义 channelID,因为 channelID 是在您创建机器人时定义的。
希望对你有帮助!如果您需要其他任何东西,请告诉我。
推荐阅读
- c# - 我正在用 C# 为 IOS 编写 Appium 测试我有一个断言要求我使用文本作为断言
- azure - 为存储帐户启用 Azure ADDS 身份验证时出现问题
- javascript - 在 Chrome 调试器中启动 onClick 功能
- git - 我在将更改推送到我的 github 存储库时遇到问题
- javascript - 引导模式不会在 Laravel 项目中关闭
- c# - Asp.Net core - 更新角色时身份并发失败
- javascript - 使用有什么区别!!vs 使用检查 null | 不明确的?在 javascript/打字稿中
- react-native - 如何创建 React Native 自定义模板?
- python - Python 的批处理脚本
- html - Bootstrap 行子继承宽度 100%?