Install: npm install redditwrap.js
Reddit.js is a promise and event based library for interacting with Reddit!
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!")
})
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
Emitted when client receives a new notification in inbox.
Parameters
inbox
Emitted when the client is ready.
Emitted when there is a new post on reddit. Listen's to all posts.
Paramaters
postData
Gets details about the current logged on user.
Returns
- Promise:
userData
Returns an array of objects of the friends the authenticated user has. Each object has name
and created
.
Returns
- Promise:
friendsList
Returns an array of objects of your mail.
Arguments
option
: A filter. One of unread
, sent
. Defaults to inbox
.
Returns
- Promise:
inbox
Get submissions on a subreddit based on sort
.
Arguments
sort
: One ofhot
,new
,rising
,controversial
,random
,top
.
Returns
- Promise:
postData
Retrieves information on a user.
Arguments
username
: The username of the user.
Returns
- Promise:
userData
object.
This method doesn't log you in. It just specifies the details the wrapper will use to authenticate your actions.
Arguments
credentials
: An object containingusername
,password
,clientID
andclientSecret
.
Search for a post by ID/fullname.
Arguments
id
: The fullname of the post withoutt3_
Returns
- Promise:
postData
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.
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
- 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
-
submitComment(comment)
Reply to the comment.
comment
: The content of your reply.
- username
- id
- dateAdded
- type
- subject
- body
- created
- parentId
- id
- author
- subreddit
-
reply(text)
Reply to the target
inbox
object.text
: Your reply.
- 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
-
submitComment(comment)
Comment on the returned post.
comment
: The content of your reply. -
save()
Save the returned post.
- username
- id
- isFriend
- joinedAt
- commentKarma
- linkKarma
- subreddit
- client
-
friend()
Adds the user as friend.
-
unfriend()
Unfriends the user.