Ad
Reddit API (Node Js) : How To Retrieve A Parent Comment In Reddit Using Snoowrap And Snoostorm?
So I am creating a reddit bot. The scenario is that A posts a comment. B replies to that comment by invoking the bot. Typically snoostorm provides a comment object for B containing info about B and the original post. How do I get a comment object for 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);
});
I've already read the docs of snoowrap. I cant find one for snoostorm. In short there is a lack of documentation or guides for creating complex reddit bots using javascript/node.js, while there are many readily available for python.
Ad
Answer
The Comment object has a property parent_id. You have to fetch the parent Comment to get the object.
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 is just a wrapper for Snoowrap.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad