Javascript 错误类型错误:对象#<;收入信息>;没有方法';发送';
我有一个机器人,它监听Slack的聊天,如果匹配,它会根据定义的身体做出反应 在下面的示例中,当我键入e2e时,它会执行函数robot.hear(/e2e/i)。我还可以看到,它进行http调用并在控制台中打印值,但res.send命令失败。返回时出现错误TypeError:Object#没有方法“send” hubot_example.jsJavascript 错误类型错误:对象#<;收入信息>;没有方法';发送';,javascript,node.js,hubot,slack-api,Javascript,Node.js,Hubot,Slack Api,我有一个机器人,它监听Slack的聊天,如果匹配,它会根据定义的身体做出反应 在下面的示例中,当我键入e2e时,它会执行函数robot.hear(/e2e/i)。我还可以看到,它进行http调用并在控制台中打印值,但res.send命令失败。返回时出现错误TypeError:Object#没有方法“send” hubot_example.js module.exports = function(robot) { robot.hear(/badger/i, function(res) {
module.exports = function(robot) {
robot.hear(/badger/i, function(res) {
res.send("Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS");
});
robot.hear(/e2e/i, function(res) {
robot.http("https://api.mycompany.com/v1/users?offset=50&limit=50").get()(function(err, res, body) {
var rateLimitRemaining;
if (res.statusCode !== 200) {
res.send("Request didn't come back HTTP 200 :(");
return;
}
console.log(body);
return res.send("Got back " + body);
});
});
};
错误:
2015-04-15T12:49:01.11-0400 [App/0] OUT [Wed Apr 15 2015 16:49:01 GMT+0000 (UTC)] ERROR TypeError: Object #<IncomingMessage> has no method 'send'
2015-04-15T12:49:01.11-0400 [App/0] OUT at /home/vcap/app/scripts/example.js:14:24
2015-04-15T12:49:01.11-0400 [App/0] OUT at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/hubot/node_modules/scoped-http-client/src/index.js:83:20)
2015-04-15T12:49:01.11-0400 [App/0] OUT at IncomingMessage.emit (events.js:117:20)
2015-04-15T12:49:01.11-0400 [App/0] OUT at _stream_readable.js:944:16
2015-04-15T12:49:01.11-0400 [App/0] OUT at process._tickCallback (node.js:448:13)
2015-04-15T12:49:01.11-0400[App/0]OUT[Wed Apr 15 2015 16:49:01 GMT+0000(UTC)]错误类型错误:对象没有“发送”方法
2015-04-15T12:49:01.11-0400[App/0]OUT at/home/vcap/App/scripts/example.js:14:24
2015-04-15T12:49:01.11-0400[App/0]输入信息时输出。(/home/vcap/app/node_modules/hubot/node_modules/scoped http client/src/index.js:83:20)
2015-04-15T12:49:01.11-0400[App/0]在IncomingMessage.emit(events.js:117:20)发布
2015-04-15T12:49:01.11-0400[App/0]在"流"上发布。js:944:16
2015-04-15T12:49:01.11-0400[App/0]在过程中退出。_tick回调(node.js:448:13)
。您无法访问两个响应对象(一个来自robot.hear()
,另一个来自robot.http()
),因为它们共享相同的标识符res
。感谢您解决了我的问题