Reddit API(Node Js):如何使用 snoowrap 和 snoostorm 在 reddit 中检索父评论?
Reddit API (Node Js) : How to retrieve a parent comment in reddit using snoowrap and snoostorm?
所以我正在创建一个 reddit 机器人。场景是 A post 发表评论。 B 通过调用机器人来回复该评论。通常,snoostorm 为 B 提供了一个注释对象,其中包含有关 B 和原始 post 的信息。如何获取A的评论对象?
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 的文档。我找不到一个用于 snoostorm 的。简而言之,缺少使用 javascript/node.js 创建复杂的 reddit 机器人的文档或指南,而 python.
有许多可用的文档或指南。
评论对象有一个 属性 parent_id。您必须获取父 Comment 才能获取对象。
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 的包装器。
所以我正在创建一个 reddit 机器人。场景是 A post 发表评论。 B 通过调用机器人来回复该评论。通常,snoostorm 为 B 提供了一个注释对象,其中包含有关 B 和原始 post 的信息。如何获取A的评论对象?
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 的文档。我找不到一个用于 snoostorm 的。简而言之,缺少使用 javascript/node.js 创建复杂的 reddit 机器人的文档或指南,而 python.
有许多可用的文档或指南。评论对象有一个 属性 parent_id。您必须获取父 Comment 才能获取对象。
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 的包装器。