Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Reddit API(Node Js):如何使用snoowrap和snoostrm在Reddit中检索父注释?_Javascript_Node.js_Bots_Reddit - Fatal编程技术网

Javascript Reddit API(Node Js):如何使用snoowrap和snoostrm在Reddit中检索父注释?

Javascript Reddit API(Node Js):如何使用snoowrap和snoostrm在Reddit中检索父注释?,javascript,node.js,bots,reddit,Javascript,Node.js,Bots,Reddit,所以我正在创建一个reddit机器人。场景是,一个用户发布一条评论。B通过调用bot回复该评论。通常,snoostrm为B提供一个comment对象,其中包含关于B和原始帖子的信息。如何获取一个注释的注释对象 const Snoowrap = require('snoowrap'); const { CommentStream } = require('snoostorm'); const client = new Snoowrap({ userAgent: 'rpffdgfh', c

所以我正在创建一个reddit机器人。场景是,一个用户发布一条评论。B通过调用bot回复该评论。通常,snoostrm为B提供一个comment对象,其中包含关于B和原始帖子的信息。如何获取一个注释的注释对象

const Snoowrap = require('snoowrap');
const { CommentStream } = require('snoostorm');

const client = new Snoowrap({
  userAgent: 'rpffdgfh',
  clientId: 'Ddhjhfjsh',
  clientSecret: 'kRHXydsgjgkjkjsjkgl',
  username: 'botname',
  password: 'botpass'
});

const canSummon = (msg) => {
  return msg && msg.toLowerCase().includes('u/botname');
};

const comments = new CommentStream(client, {
  subreddit: 'testingground4bots',
  limit: 10,
  pollTime: 10000
});

//info about original comment (in this case B)
comments.on('item', (item) => {
  if (!canSummon(item.body)) return;
  console.log(item);
}); 

我已经看过snoowrap的文件了。我找不到适合斯诺斯托姆的。简言之,缺乏使用javascript/node.js创建复杂reddit机器人程序的文档或指南,而python有许多现成的工具。

注释对象具有属性parent\u id。您必须获取父注释才能获取对象

comments.on('item', (item) => {
    if (!canSummon(item.body)) return;
    console.log(item);
    client.getComment(item.parent_id).fetch().then(parentComment => {
        console.log(parentComment.body);
    });
});

Snoostorm只是Snoowrap的一个包装。

是的,我不久前在Snoowrap的github问题页面上询问过这个问题后才得到这个答案。我从没想到会有人回答我的问题。谢谢