gpt4 book ai didi

javascript - 通过谷歌应用程序脚本向不和谐发送消息

转载 作者:行者123 更新时间:2023-11-29 23:30:10 25 4
gpt4 key购买 nike

当某个事件被触发时,我想通过谷歌应用程序脚本在不和谐 channel 中发送机器人消息,但我不知道从哪里开始。这可能吗?如果没有,有没有办法通过 github 做到这一点?

编辑:我已经弄清楚如何获取 OAuth token ,现在我该如何让机器人发送消息?

最佳答案

我知道 OP 几乎不可能仍然需要这个答案,但我把它放在这里是为了让其他用谷歌搜索这个问题的人能够找到答案

var webhooks = {
test: "Obtain a webhook for the channel you'd like and put it here."
};

function sendMessage(message, channel)
{
if(webhooks.hasOwnProperty(channel))
var url = webhooks[channel];
else {
Logger.log("Error Sending Message to Channel " + channel);
return "NoStoredWebhookException";
}

var payload = JSON.stringify({content: message});

var params = {
headers: {"Content-Type": "application/x-www-form-urlencoded"},
method: "POST",
payload: payload,
muteHttpExceptions: true
};

var res = UrlFetchApp.fetch(url, params);
Logger.log(res.getContentText());
}

// to call and send a message
sendMessage("Hi!", "test");

这是我通常用来发送消息的方式。不幸的是,据我所知,无法从 webhook 接收触发器。

注意:以上答案引用了与 Google Apps 脚本不兼容的 discord.js

关于javascript - 通过谷歌应用程序脚本向不和谐发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47639463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com