Skip to content

dowzhong/redditwrap.js

Repository files navigation

reddit.js

npm npm Travis branch Known Vulnerabilities

Events

Methods

Types


I will not be responsible for how you use this wrapper!

Install: npm install redditwrap.js

Reddit.js is a promise and event based library for interacting with Reddit!

Getting started with making a basic post:

const redditjs = require('reddit.js')
let reddit = new redditjs({
  useragent: USERAGENT,
  username: USERNAME,
  password: PASSWORD,
  clientID: YOUR-SCRIPT-TYPE-APP-ID,
  clientSecret: YOUR-SCRIPT-TYPE-APP-SECRET
})
reddit.on('ready', () =>{
  reddit.submitTextPost('test', 'Hello World!', 'My first text post!')
    .then(data =>{
      console.log(data)
    })
    .catch(err => {
      console.log(err)
    })
})

reddit.on('message', message =>{
  message.reply("beep boop!")
})

Documentation

Events

comment

Emmitted when there is a new comment. Listens to r/all. (Needs a bit of fixing. Some subreddits might not appear for some reason.)

Parameters

commentData


message

Emitted when client receives a new notification in inbox.

Parameters

inbox


ready

Emitted when the client is ready.


submission

Emitted when there is a new post on reddit. Listen's to all posts.

Paramaters

postData


Methods

getCurrentUser()

Gets details about the current logged on user.

Returns

  • Promise: userData

getFriends()

Returns an array of objects of the friends the authenticated user has. Each object has name and created.

Returns

  • Promise: friendsList

getInbox([option])

Returns an array of objects of your mail.

Arguments

option: A filter. One of unread, sent. Defaults to inbox.

Returns

  • Promise: inbox

getPosts(subreddit, [sort])

Get submissions on a subreddit based on sort.

Arguments

  • sort: One of hot, new, rising, controversial, random, top.

Returns

  • Promise: postData

getUser(username)

Retrieves information on a user.

Arguments

  • username: The username of the user.

Returns

  • Promise: userData object.

login(credentials)

This method doesn't log you in. It just specifies the details the wrapper will use to authenticate your actions.

Arguments

  • credentials: An object containing username, password, clientID and clientSecret.

searchPost(id)

Search for a post by ID/fullname.

Arguments

  • id: The fullname of the post without t3_

Returns

  • Promise: postData

submitComment(targetID, comment)

Reply to a post/comment.

Arguments

targetID: The fullname of the target. Please refer to Reddit documentation if you don't know what that is. comment: The contents of your comment as a string.


submitTextPost(subreddit, title, content)

Submit a new text/selfpost to a subreddit.

Arguments

  • subreddit: The subreddit you'd like to post in.
  • title: The title of the post.
  • content: The content of your post.

Returns

  • Promise: successData

Types

commentData

Properties

  • subreddit_id
  • approved_at_utc
  • edited
  • banned_by
  • removal_reason
  • link_id
  • link_author
  • likes
  • replies
  • user_reports
  • saved
  • id
  • banned_at_utc
  • gilded
  • archived
  • report_reasons
  • author
  • num_comments
  • can_mod_post
  • parent_id
  • score
  • approved_by
  • over_18
  • collapsed
  • body
  • link_title
  • author
  • downs
  • is_submitter
  • collapsed_reason
  • body_html
  • distinguished
  • quarantine
  • can_gild
  • subreddit
  • name
  • score_hidden
  • num_reports
  • link_permalink
  • stickied
  • created
  • author_flair_text
  • link_url
  • created_utc
  • subreddit_name_prefixed
  • controversiality
  • mod_reports
  • subreddit_type
  • ups

Methods

  • submitComment(comment)

        Reply to the comment.

        comment: The content of your reply.


friendsList

Properties

  • username
  • id
  • dateAdded

inbox

Properties

  • type
  • subject
  • body
  • created
  • parentId
  • id
  • author
  • subreddit

Methods

  • reply(text)

        Reply to the target inbox object.

        text: Your reply.


postData

Properties

  • domain
  • approved_at_utc
  • banned_by
  • media_embed
  • thumbnail_width
  • subreddit
  • selftext_html
  • selftext
  • likes
  • suggested_sort
  • user_reports
  • secure_media
  • link_flair_text
  • id
  • banned_at_utc
  • view_count
  • archived
  • clicked
  • report_reasons
  • title
  • media
  • mod_reports
  • can_mod_post
  • author_flair_text
  • score
  • approved_by
  • over_18
  • hidden
  • preview
  • thumbnail
  • subreddit_id
  • edited
  • link_flair_css_class
  • author_flair_css_class
  • contest_mode
  • gilded
  • downs
  • brand_safe
  • secure_media_embed
  • saved
  • removal_reason
  • post_hint
  • stickied
  • can_gild
  • thumbnail_height
  • parent_whitelist_status
  • name
  • spoiler
  • permalink
  • subreddit_type
  • locked
  • hide_score
  • created
  • url
  • whitelist_status
  • quarantine
  • author
  • created_utc
  • subreddit_name_prefixed
  • ups
  • num_comments
  • is_self
  • visited
  • num_reports
  • is_video
  • distinguished

Methods

  • submitComment(comment)

        Comment on the returned post.

        comment: The content of your reply.

  • save()

        Save the returned post.


userData

Properties

  • username
  • id
  • isFriend
  • joinedAt
  • commentKarma
  • linkKarma
  • subreddit
  • client

Methods

  • friend()

        Adds the user as friend.

  • unfriend()

        Unfriends the user.

About

Simple Unofficial wrapper for Reddit

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published