new Subreddit()
Example
// Get a subreddit by name r.getSubreddit('AskReddit')
Extends
Methods
-
deleteAllUserFlairTemplates()
Deletes all of this subreddit's user flair templates
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteAllUserFlairTemplates()
-
deleteAllLinkFlairTemplates()
Deletes all of this subreddit's link flair templates
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteAllLinkFlairTemplates()
-
deleteFlairTemplate(options)
Deletes one of this subreddit's flair templates
-
Parameters:
Name Type Description options
object Properties
Name Type Description flair_template_id
string The ID of the template that should be deleted
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteFlairTemplate({flair_template_id: 'fdfd8532-c91e-11e5-b4d4-0e082084d721'})
-
createUserFlairTemplate(options)
Creates a new user flair template for this subreddit
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description text
string The flair text for this template
cssClass
string <optional>
'' The CSS class for this template
textEditable
boolean <optional>
false Determines whether users should be able to edit their flair text when it has this template
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').createUserFlairTemplate({text: 'Some Flair Text', cssClass: 'some-css-class'})
-
createLinkFlairTemplate(options)
Creates a new link flair template for this subreddit
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description text
string The flair text for this template
cssClass
string <optional>
'' The CSS class for this template
textEditable
boolean <optional>
false Determines whether users should be able to edit the flair text of their links when it has this template
Returns:
A Promise that fulfills with this Subredit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').createLinkFlairTemplate({text: 'Some Flair Text', cssClass: 'some-css-class'})
-
getLinkFlairTemplates( [linkId])
Gets the flair templates for the subreddit or a given link.
-
Parameters:
Name Type Argument Description linkId
string <optional>
The link's base36 ID
Returns:
An Array of flair template options
- Type
- Promise
Example
r.getSubreddit('snoowrap').getLinkFlairTemplates('4fp36y').then(console.log) // => [ { flair_css_class: '', // flair_template_id: 'fdfd8532-c91e-11e5-b4d4-0e082084d721', // flair_text_editable: true, // flair_position: 'right', // flair_text: '' }, // { flair_css_class: '', // flair_template_id: '03821f62-c920-11e5-b608-0e309fbcf863', // flair_text_editable: true, // flair_position: 'right', // flair_text: '' }, // ... // ]
-
getUserFlairTemplates()
Gets the list of user flair templates on this subreddit.
-
Returns:
An Array of user flair templates
- Type
- Promise
Example
r.getSubreddit('snoowrap').getUserFlairTemplates().then(console.log) // => [ { flair_css_class: '', // flair_template_id: 'fdfd8532-c91e-11e5-b4d4-0e082084d721', // flair_text_editable: true, // flair_position: 'right', // flair_text: '' }, // { flair_css_class: '', // flair_template_id: '03821f62-c920-11e5-b608-0e309fbcf863', // flair_text_editable: true, // flair_position: 'right', // flair_text: '' }, // ... // ]
-
deleteUserFlair(name)
Clears a user's flair on this subreddit.
-
Parameters:
Name Type Description name
string The user's name
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteUserFlair('actually_an_aardvark')
-
getUserFlair(name)
Gets a user's flair on this subreddit.
-
Parameters:
Name Type Description name
string The user's name
Returns:
An object representing the user's flair
- Type
- Promise
Example
r.getSubreddit('snoowrap').getUserFlair('actually_an_aardvark').then(console.log) // => { flair_css_class: '', // flair_template_id: 'fdfd8532-c91e-11e5-b4d4-0e082084d721', // flair_text: '', // flair_position: 'right' // }
-
setMultipleUserFlairs(flairArray)
Sets multiple user flairs at the same time
-
Due to the behavior of the reddit API endpoint that this function uses, if any of the provided user flairs are invalid, reddit will make note of this in its response, but it will still attempt to set the remaining user flairs. If this occurs, the Promise returned by snoowrap will be rejected, and the rejection reason will be an array containing the 'error' responses from reddit.
Parameters:
Name Type Description flairArray
Array.<object> flairArray[].name
string A user's name
flairArray[].text
string The flair text to assign to this user
flairArray[].cssClass
string The flair CSS class to assign to this user
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').setMultipleUserFlairs([ {name: 'actually_an_aardvark', text: "this is /u/actually_an_aardvark's flair text", cssClass: 'some-css-class'}, {name: 'snoowrap_testing', text: "this is /u/snoowrap_testing's flair text", cssClass: 'some-css-class'} ]); // the above request gets completed successfully r.getSubreddit('snoowrap').setMultipleUserFlairs([ {name: 'actually_an_aardvark', text: 'foo', cssClass: 'valid-css-class'}, {name: 'snoowrap_testing', text: 'bar', cssClass: "this isn't a valid css class"}, {name: 'not_an_aardvark', text: 'baz', cssClass: "this also isn't a valid css class"} ]) // the Promise from the above request gets rejected, with the following rejection reason: [ { status: 'skipped', errors: { css: 'invalid css class `this isn\'t a valid css class\', ignoring' }, ok: false, warnings: {} }, { status: 'skipped', errors: { css: 'invalid css class `this also isn\'t a valid css class\', ignoring' }, ok: false, warnings: {} } ] // note that /u/actually_an_aardvark's flair still got set by the request, even though the other two flairs caused errors.
-
getUserFlairList(options)
Gets a list of all user flairs on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description name
string <optional>
A specific username to jump to
Returns:
A Listing containing user flairs
- Type
- Promise
Example
r.getSubreddit('snoowrap').getUserFlairList().then(console.log) // => Listing [ // { flair_css_class: null, // user: 'not_an_aardvark', // flair_text: 'Isn\'t an aardvark' }, // { flair_css_class: 'some-css-class', // user: 'actually_an_aardvark', // flair_text: 'this is /u/actually_an_aardvark\'s flair text' }, // { flair_css_class: 'some-css-class', // user: 'snoowrap_testing', // flair_text: 'this is /u/snoowrap_testing\'s flair text' } // ]
-
configureFlair(options)
Configures the flair settings for this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description userFlairEnabled
boolean Determines whether user flair should be enabled
userFlairPosition
string Determines the orientation of user flair relative to a given username. This should be either the string 'left' or the string 'right'.
userFlairSelfAssignEnabled
boolean Determines whether users should be able to edit their own flair
linkFlairPosition
string Determines the orientation of link flair relative to a link title. This should be either 'left' or 'right'.
linkFlairSelfAssignEnabled
boolean Determines whether users should be able to edit the flair of their submissions.
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').configure_flair({ userFlairEnabled: true, userFlairPosition: 'left', userFlairSelfAssignEnabled: false, linkFlairPosition: 'right', linkFlairSelfAssignEnabled: false })
-
getMyFlair()
Gets the requester's flair on this subreddit.
-
Returns:
An object representing the requester's current flair
- Type
- Promise
Example
r.getSubreddit('snoowrap').getMyFlair().then(console.log) // => { flair_css_class: 'some-css-class', // flair_template_id: null, // flair_text: 'this is /u/snoowrap_testing\'s flair text', // flair_position: 'right' // }
-
selectMyFlair(options)
Sets the requester's flair on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description flair_template_id
string A flair template ID to use. (This should be obtained beforehand using
getUserFlairTemplates
.)text
string <optional>
The flair text to use. (This is only necessary/useful if the given flair template has the
text_editable
property set totrue
.)Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').selectMyFlair({flair_template_id: 'fdfd8532-c91e-11e5-b4d4-0e082084d721'})
-
showMyFlair()
Makes the requester's flair visible on this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').showMyFlair()
-
hideMyFlair()
Makes the requester's flair invisible on this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').hideMyFlair()
-
submitSelfpost(options)
Creates a new selfpost on this subreddit.
-
Parameters:
Name Type Description options
object An object containing details about the submission
Properties
Name Type Argument Default Description title
string The title of the submission
text
string <optional>
The selftext of the submission
sendReplies
boolean <optional>
true Determines whether inbox replies should be enabled for this submission
captchaIden
string <optional>
A captcha identifier. This is only necessary if the authenticated account requires a captcha to submit posts and comments.
captchaResponse
string <optional>
The response to the captcha with the given identifier
Returns:
The newly-created Submission object
- Type
- Promise
Example
r.getSubreddit('snoowrap').submitSelfpost({title: 'this is a selfpost', text: "hi, how's it going?"}).then(console.log) // => Submission { name: 't3_4abmsz' }
-
submitLink(options)
Creates a new link submission on this subreddit.
-
Parameters:
Name Type Description options
object An object containing details about the submission
Properties
Name Type Argument Default Description title
string The title of the submission
url
string The url that the link submission should point to
sendReplies
boolean <optional>
true Determines whether inbox replies should be enabled for this submission
resubmit
boolean <optional>
true If this is false and same link has already been submitted to this subreddit in the past, reddit will return an error. This could be used to avoid accidental reposts.
captchaIden
string <optional>
A captcha identifier. This is only necessary if the authenticated account requires a captcha to submit posts and comments.
captchaResponse
string <optional>
The response to the captcha with the given identifier
Returns:
The newly-created Submission object
- Type
- Promise
Example
r.getSubreddit('snoowrap').submitLink({title: 'I found a cool website', url: 'https://google.com'}).then(console.log) // => Submission { name: 't3_4abmsz' }
-
submitCrosspost(options)
Creates a new crosspost submission on this subreddit
-
NOTE: To create a crosspost, the authenticated account must be subscribed to the subreddit where the crosspost is being submitted, and that subreddit be configured to allow crossposts.
Parameters:
Name Type Description options
object An object containing details about the submission
Properties
Name Type Argument Default Description title
string The title of the crosspost
originalPost
string | Submission A Submission object or a post ID for the original post which is being crossposted
sendReplies
boolean <optional>
true Determines whether inbox replies should be enabled for this submission
resubmit
boolean <optional>
true If this is false and same link has already been submitted to this subreddit in the past, reddit will return an error. This could be used to avoid accidental reposts.
Returns:
The newly-created Submission object
- Type
- Promise
Example
await r.getSubreddit('snoowrap').submitCrosspost({ title: 'I found an interesting post', originalPost: '6vths0' }) // => Submission { name: 't3_4abmsz' }
-
getHot( [options])
Gets a Listing of hot posts on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Returns:
A Listing containing the retrieved submissions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getHot().then(console.log) // => Listing [ // Submission { ... }, // Submission { ... }, // ... // ]
-
getNew( [options])
Gets a Listing of new posts on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Returns:
A Listing containing the retrieved submissions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getNew().then(console.log) // => Listing [ // Submission { ... }, // Submission { ... }, // ... // ]
-
getNewComments( [options])
Gets a Listing of new comments on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Returns:
A Listing containing the retrieved comments
- Type
- Promise
Example
r.getSubreddit('snoowrap').getNewComments().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // ... // ]
-
getRandomSubmission()
Gets a single random Submission from this subreddit.
-
Note: This function will not work when snoowrap is running in a browser, because the reddit server sends a redirect which cannot be followed by a CORS request.
Returns:
The retrieved Submission object
- Type
- Promise
Example
r.getSubreddit('snoowrap').getRandomSubmission().then(console.log) // => Submission { ... }
-
getTop( [options])
Gets a Listing of top posts on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description time
string <optional>
Describes the timespan that posts should be retrieved from. Should be one of
hour, day, week, month, year, all
Returns:
A Listing containing the retrieved submissions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getTop({time: 'all'}).then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // ... // ]
-
getControversial( [options])
Gets a Listing of controversial posts on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description time
string <optional>
Describes the timespan that posts should be retrieved from. Should be one of
hour, day, week, month, year, all
Returns:
A Listing containing the retrieved submissions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getControversial({time: 'week'}).then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // ... // ]
-
getRising( [options])
Gets a Listing of top posts on this subreddit.
-
Parameters:
Name Type Argument Description options
object <optional>
Options for the resulting Listing
Returns:
A Listing containing the retrieved submissions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getRising().then(console.log) // => Listing [ // Submission { ... }, // Submission { ... }, // ... // ]
-
getModmail( [options])
Gets the moderator mail for this subreddit.
-
Parameters:
Name Type Argument Description options
object <optional>
Options for the resulting Listing
Returns:
A Listing containing PrivateMessage objects
- Type
- Promise
Example
r.getSubreddit('snoowrap').getModmail().then(console.log)
-
getNewModmailConversations( [options])
Gets a list of ModmailConversations from the subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Returns:
A Listing containing Subreddits
- Type
- Promise.<Listing.<ModmailConversation>>
Example
r.getSubreddit('snoowrap').getNewModmailConversations({limit: 2}).then(console.log) // => Listing [ // ModmailConversation { messages: [...], objIds: [...], subject: 'test subject', ... }, // ModmailConversation { messages: [...], objIds: [...], subject: 'test subject', ... } // ]
-
getModerationLog( [options])
Gets the moderation log for this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description mods
Array.<string> <optional>
An array of moderator names that the results should be restricted to
type
string <optional>
Restricts the results to the specified type. This should be one of
banuser, unbanuser, removelink, approvelink, removecomment, approvecomment, addmoderator, invitemoderator, uninvitemoderator, acceptmoderatorinvite, removemoderator, addcontributor, removecontributor, editsettings, editflair, distinguish, marknsfw, wikibanned, wikicontributor, wikiunbanned, wikipagelisted, removewikicontributor, wikirevise, wikipermlevel, ignorereports, unignorereports, setpermissions, setsuggestedsort, sticky, unsticky, setcontestmode, unsetcontestmode, lock, unlock, muteuser, unmuteuser, createrule, editrule, deleterule, spoiler, unspoiler
Returns:
A Listing containing moderation actions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getModerationLog().then(console.log) // => Listing [ // ModAction { description: null, mod: 'snoowrap_testing', action: 'editflair', ... } // ModAction { description: null, mod: 'snoowrap_testing', action: 'approvecomment', ... } // ModAction { description: null, mod: 'snoowrap_testing', action: 'createrule', ... } // ]
-
getReports( [options])
Gets a list of reported items on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description only
string <optional>
Restricts the Listing to the specified type of item. One of
links, comments
Returns:
A Listing containing reported items
- Type
- Promise
Example
r.getSubreddit('snoowrap').getReports().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // Submission { ... }, // ... // ]
-
getSpam( [options])
Gets a list of removed items on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description only
string <optional>
Restricts the Listing to the specified type of item. One of
links, comments
Returns:
A Listing containing removed items
- Type
- Promise
Example
r.getSubreddit('snoowrap').getSpam().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // Submission { ... }, // ... // ]
-
getModqueue( [options])
Gets a list of items on the modqueue on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description only
string <optional>
Restricts the Listing to the specified type of item. One of
links, comments
Returns:
A Listing containing items on the modqueue
- Type
- Promise
Example
r.getSubreddit('snoowrap').getModqueue().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // Submission { ... }, // ... // ]
-
getUnmoderated( [options])
Gets a list of unmoderated items on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description only
string <optional>
Restricts the Listing to the specified type of item. One of
links, comments
Returns:
A Listing containing unmoderated items
- Type
- Promise
Example
r.getSubreddit('snoowrap').getUnmoderated().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // Submission { ... }, // ... // ]
-
getEdited( [options])
Gets a list of edited items on this subreddit.
-
Parameters:
Name Type Argument Default Description options
object <optional>
{} Options for the resulting Listing
Properties
Name Type Argument Description only
string <optional>
Restricts the Listing to the specified type of item. One of
links, comments
Returns:
A Listing containing edited items
- Type
- Promise
Example
r.getSubreddit('snoowrap').getEdited().then(console.log) // => Listing [ // Comment { ... }, // Comment { ... }, // Submission { ... }, // ... // ]
-
acceptModeratorInvite()
Accepts an invite to become a moderator of this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').acceptModeratorInvite()
-
leaveModerator()
Abdicates moderator status on this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').leaveModerator()
-
leaveContributor()
Abdicates approved submitter status on this subreddit.
-
Returns:
A Promise that resolves with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').leaveContributor()
-
getStylesheet()
Gets a subreddit's CSS stylesheet.
-
Note: This method will return a 404 error if the subreddit in question does not have a custom stylesheet.
Returns:
A Promise for a string containing the subreddit's CSS.
- Type
- Promise
Example
r.getSubreddit('snoowrap').getStylesheet().then(console.log) // => '.md blockquote,.md del,body{color:#121212}.usertext-body ... '
-
search(options)
Conducts a search of reddit submissions, restricted to this subreddit.
-
Parameters:
Name Type Description options
object Search options. Can also contain options for the resulting Listing.
Properties
Name Type Argument Default Description query
string The search query
time
string <optional>
Describes the timespan that posts should be retrieved frome. One of
hour, day, week, month, year, all
sort
string <optional>
Determines how the results should be sorted. One of
relevance, hot, top, new, comments
syntax
string <optional>
'plain' Specifies a syntax for the search. One of
cloudsearch, lucene, plain
Returns:
A Listing containing the search results.
- Type
- Promise
Example
r.getSubreddit('snoowrap').search({query: 'blah', sort: 'year'}).then(console.log) // => Listing [ // Submission { ... }, // Submission { ... }, // ... // ]
-
getBannedUsers(options)
Gets the list of banned users on this subreddit.
-
Parameters:
Name Type Description options
object Filtering options. Can also contain options for the resulting Listing.
Properties
Name Type Description name
string A username on the list to jump to.
Returns:
A Listing of users
- Type
- Promise
Example
r.getSubreddit('snoowrap').getBannedUsers().then(console.log) // => Listing [ // { date: 1461720936, note: '', name: 'actually_an_aardvark', id: 't2_q3519' } // ... // ]
-
getMutedUsers(options)
Gets the list of muted users on this subreddit.
-
Parameters:
Name Type Description options
object Filtering options. Can also contain options for the resulting Listing.
Properties
Name Type Description name
string A username on the list to jump to.
Returns:
A Listing of users
- Type
- Promise
Example
r.getSubreddit('snoowrap').getBannedUsers().then(console.log) // => Listing [ // { date: 1461720936, name: 'actually_an_aardvark', id: 't2_q3519' } // ... // ]
-
getWikibannedUsers(options)
Gets the list of users banned from this subreddit's wiki.
-
Parameters:
Name Type Description options
object Filtering options. Can also contain options for the resulting Listing.
Properties
Name Type Description name
string A username on the list to jump to.
Returns:
A Listing of users
- Type
- Promise
Example
r.getSubreddit('snoowrap').getWikibannedUsers().then(console.log) // => Listing [ // { date: 1461720936, note: '', name: 'actually_an_aardvark', id: 't2_q3519' } // ... // ]
-
getContributors(options)
Gets the list of approved submitters on this subreddit.
-
Parameters:
Name Type Description options
object Filtering options. Can also contain options for the resulting Listing.
Properties
Name Type Description name
string A username on the list to jump to.
Returns:
A Listing of users
- Type
- Promise
Example
r.getSubreddit('snoowrap').getContributors().then(console.log) // => Listing [ // { date: 1461720936, name: 'actually_an_aardvark', id: 't2_q3519' } // ... // ]
-
getWikiContributors(options)
Gets the list of approved wiki submitters on this subreddit .
-
Parameters:
Name Type Description options
object Filtering options. Can also contain options for the resulting Listing.
Properties
Name Type Description name
string A username on the list to jump to.
Returns:
A Listing of users
- Type
- Promise
Example
r.getSubreddit('snoowrap').getWikiContributors().then(console.log) // => Listing [ // { date: 1461720936, name: 'actually_an_aardvark', id: 't2_q3519' } // ... // ]
-
getModerators(options)
Gets the list of moderators on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description name
string <optional>
The name of a user to find in the list
Returns:
An Array of RedditUsers representing the moderators of this subreddit
- Type
- Promise
Example
r.getSubreddit('AskReddit').getModerators().then(console.log) // => [ // RedditUser { date: 1453862639, mod_permissions: [ 'all' ], name: 'not_an_aardvark', id: 't2_k83md' }, // ... // ]
-
deleteBanner()
Deletes the banner for this Subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteBanner()
-
deleteHeader()
Deletes the header image for this Subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteHeader()
-
deleteIcon()
Deletes this subreddit's icon.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteIcon()
-
deleteImage(options)
Deletes an image from this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description imageName
string The name of the image.
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').deleteImage()
-
getSettings()
Gets this subreddit's current settings.
-
Returns:
An Object containing this subreddit's current settings.
- Type
- Promise
Example
r.getSubreddit('snoowrap').getSettings().then(console.log) // => SubredditSettings { default_set: true, submit_text: '', subreddit_type: 'private', ... }
-
editSettings(options)
Edits this subreddit's settings.
-
Parameters:
Name Type Description options
object An Object containing {[option name]: new value} mappings of the options that should be modified. Any omitted option names will simply retain their previous values.
Properties
Name Type Argument Default Description title
string The text that should appear in the header of the subreddit
public_description
string The text that appears with this Subreddit on the search page, or on the blocked-access page if this subreddit is private. (500 characters max)
description
string The sidebar text for the subreddit. (5120 characters max)
submit_text
string <optional>
'' The text to show below the submission page (1024 characters max)
hide_ads
boolean <optional>
false Determines whether ads should be hidden on this subreddit. (This is only allowed for gold-only subreddits.)
lang
string <optional>
'en' The language of the subreddit (represented as an IETF language tag)
type
string <optional>
'public' Determines who should be able to access the subreddit. This should be one of
public, private, restricted, gold_restricted, gold_only, archived, employees_only
.link_type
string <optional>
'any' Determines what types of submissions are allowed on the subreddit. This should be one of
any, link, self
.submit_link_label
string <optional>
Custom text to display on the button that submits a link. If this is omitted, the default text will be displayed.
submit_text_label
string <optional>
Custom text to display on the button that submits a selfpost. If this is omitted, the default text will be displayed.
wikimode
string <optional>
'modonly' Determines who can edit wiki pages on the subreddit. This should be one of
modonly, anyone, disabled
.wiki_edit_karma
number <optional>
0 The minimum amount of subreddit karma needed for someone to edit this subreddit's wiki. (This is only relevant if
options.wikimode
is set toanyone
.)wiki_edit_age
number <optional>
0 The minimum account age (in days) needed for someone to edit this subreddit's wiki. (This is only relevant if
options.wikimode
is set toanyone
.)spam_links
string <optional>
'high' The spam filter strength for links on this subreddit. This should be one of
low, high, all
.spam_selfposts
string <optional>
'high' The spam filter strength for selfposts on this subreddit. This should be one of
low, high, all
.spam_comments
string <optional>
'high' The spam filter strength for comments on this subreddit. This should be one of
low, high, all
.over_18
boolean <optional>
false Determines whether this subreddit should be classified as NSFW
allow_top
boolean <optional>
true Determines whether the new subreddit should be able to appear in /r/all and trending subreddits
show_media
boolean <optional>
false Determines whether image thumbnails should be enabled on this subreddit
show_media_preview
boolean <optional>
true Determines whether media previews should be expanded by default on this subreddit
allow_images
boolean <optional>
true Determines whether image uploads and links to image hosting sites should be enabled on this subreddit
exclude_banned_modqueue
boolean <optional>
false Determines whether posts by site-wide banned users should be excluded from the modqueue.
public_traffic
boolean <optional>
false Determines whether the /about/traffic page for this subreddit should be viewable by anyone.
collapse_deleted_comments
boolean <optional>
false Determines whether deleted and removed comments should be collapsed by default
suggested_comment_sort
string <optional>
The suggested comment sort for the subreddit. This should be one of
confidence, top, new, controversial, old, random, qa
.If left blank, there will be no suggested sort, which means that users will see the sort method that is set in their own preferences (usuallyconfidence
.)spoilers_enabled
boolean <optional>
false Determines whether users can mark their posts as spoilers
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').editSettings({submit_text: 'Welcome! Please be sure to read the rules.'})
-
getRecommendedSubreddits( [options])
Gets a list of recommended other subreddits given this one.
-
Parameters:
Name Type Argument Description options
object <optional>
Properties
Name Type Argument Default Description omit
Array <optional>
[] An Array of subreddit names that should be excluded from the listing.
Returns:
An Array of subreddit names
- Type
- Promise
Example
r.getSubreddit('AskReddit').getRecommendedSubreddits().then(console.log); // [ 'TheChurchOfRogers', 'Sleepycabin', ... ]
-
getSubmitText()
Gets the submit text (which displays on the submission form) for this subreddit.
-
Returns:
The submit text, represented as a string.
- Type
- Promise
Example
r.getSubreddit('snoowrap').getSubmitText().then(console.log) // => 'Welcome! Please be sure to read the rules.'
-
updateStylesheet(options)
Updates this subreddit's stylesheet.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description css
string The new contents of the stylesheet
reason
string <optional>
The reason for the change (256 characters max)
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').updateStylesheet({css: 'body {color:#00ff00;}', reason: 'yay green'})
-
subscribe()
Subscribes to this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').subscribe()
-
unsubscribe()
Unsubscribes from this subreddit.
-
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').unsubscribe()
-
uploadStylesheetImage(options)
Uploads an image for use in this subreddit's stylesheet.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description name
string The name that the new image should have in the stylesheet
file
string | stream.Readable The image file that should get uploaded. This should either be the path to an image file, or a ReadableStream in environments (e.g. browsers) where the filesystem is unavailable.
imageType
string <optional>
'png' Determines how the uploaded image should be stored. One of
png, jpg
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').uploadSubredditImage({name: 'the cookie monster', file: './cookie_monster.png'})
-
uploadHeaderImage(options)
Uploads an image to use as this subreddit's header.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description file
string | stream.Readable The image file that should get uploaded. This should either be the path to an image file, or a ReadableStream for environments (e.g. browsers) where the filesystem is unavailable.
imageType
string <optional>
'png' Determines how the uploaded image should be stored. One of
png, jpg
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').uploadHeaderImage({name: 'the cookie monster', file: './cookie_monster.png'})
-
uploadIcon(options)
Uploads an image to use as this subreddit's mobile icon.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description file
string | stream.Readable The image file that should get uploaded. This should either be the path to an image file, or a ReadableStream for environments (e.g. browsers) where the filesystem is unavailable.
imageType
string <optional>
'png' Determines how the uploaded image should be stored. One of
png, jpg
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').uploadIcon({name: 'the cookie monster', file: './cookie_monster.png'})
-
uploadBannerImage(options)
Uploads an image to use as this subreddit's mobile banner.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Default Description file
string | stream.Readable The image file that should get uploaded. This should either be the path to an image file, or a ReadableStream for environments (e.g. browsers) where the filesystem is unavailable.
imageType
string <optional>
'png' Determines how the uploaded image should be stored. One of
png, jpg
Returns:
A Promise that fulfills with this Subreddit when the request is complete.
- Type
- Promise
Example
r.getSubreddit('snoowrap').uploadBannerImage({name: 'the cookie monster', file: './cookie_monster.png'})
-
getRules()
Gets information on this subreddit's rules.
-
Returns:
A Promise that fulfills with information on this subreddit's rules.
- Type
- Promise
Example
r.getSubreddit('snoowrap').getRules().then(console.log) // => { rules: [ { kind: 'all', short_name: 'Rule 1: No violating rule 1', description: 'Breaking this rule is not allowed.', ... }, ... ], site_rules: [ 'Spam', 'Personal and confidential information'', 'Threatening, harassing, or inciting violence' ] }
-
getSticky( [options])
Gets the stickied post on this subreddit, or throws a 404 error if none exists.
-
Parameters:
Name Type Argument Description options
object <optional>
Properties
Name Type Argument Default Description num
number <optional>
1 The number of the sticky to get. Should be either
1
(first sticky) or2
(second sticky).Returns:
A Submission object representing this subreddit's stickied submission
- Type
- Promise
Example
r.getSubreddit('snoowrap').getSticky({num: 2}) // => Submission { ... }
-
inviteModerator(options)
Invites the given user to be a moderator of this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description name
string The username of the account that should be invited
permissions
Array <optional>
The moderator permissions that this user should have. This should be an array containing some combination of
"wiki", "posts", "access", "mail", "config", "flair"
. To add a moderator with full permissions, omit this property entirely.Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').inviteModerator({name: 'actually_an_aardvark', permissions: ['posts', 'wiki']})
-
revokeModeratorInvite(options)
Revokes an invitation for the given user to be a moderator.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account whose invitation should be revoked
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').revokeModeratorInvite({name: 'actually_an_aardvark'})
-
removeModerator(options)
Removes the given user's moderator status on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account whose moderator status should be removed
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').removeModerator({name: 'actually_an_aardvark'})
-
addContributor(options)
Makes the given user an approved submitter of this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be given this status
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').addContributor({name: 'actually_an_aardvark'})
-
removeContributor(options)
Revokes this user's approved submitter status on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account whose status should be revoked
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').removeContributor({name: 'actually_an_aardvark'})
-
banUser(options)
Bans the given user from this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description name
string The username of the account that should be banned
banMessage
string <optional>
The ban message. This will get sent to the user in a private message, alerting them that they have been banned.
banReason
string <optional>
A string indicating which rule the banned user broke (100 characters max)
duration
number <optional>
The duration of the ban, in days. For a permanent ban, omit this parameter.
banNote
string <optional>
A note that appears on the moderation log, usually used to indicate the reason for the ban. This is not visible to the banned user. (300 characters max)
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').banUser({name: 'actually_an_aardvark', banMessage: 'You are now banned LOL'})
-
unbanUser(options)
Unbans the given user from this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be unbanned
Returns:
A Promise that fulfills when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').unbanUser({name: 'actually_an_aardvark'})
-
muteUser(options)
Mutes the given user from messaging this subreddit for 72 hours.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be muted
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').muteUser({name: 'actually_an_aardvark'})
-
unmuteUser(options)
Unmutes the given user from messaging this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be muted
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').unmuteUser({name: 'actually_an_aardvark'})
-
wikibanUser(options)
Bans the given user from editing this subreddit's wiki.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be wikibanned
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').wikibanUser({name: 'actually_an_aardvark'})
-
unwikibanUser(options)
Unbans the given user from editing this subreddit's wiki.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be unwikibanned
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').unwikibanUser({name: 'actually_an_aardvark'})
-
addWikiContributor(options)
Adds the given user to this subreddit's list of approved wiki editors.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account that should be given approved editor status
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').addWikiContributor({name: 'actually_an_aardvark'})
-
removeWikiContributor(options)
Removes the given user from this subreddit's list of approved wiki editors.
-
Parameters:
Name Type Description options
object Properties
Name Type Description name
string The username of the account whose approved editor status should be revoked
Returns:
A Promise that fulfills with this Subreddit when the request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').removeWikiContributor({name: 'actually_an_aardvark'})
-
setModeratorPermissions(options)
Sets the permissions for a given moderator on this subreddit.
-
Parameters:
Name Type Description options
object Properties
Name Type Argument Description name
string The username of the moderator whose permissions are being changed
permissions
Array <optional>
The new moderator permissions that this user should have. This should be an array containing some combination of
"wiki", "posts", "access", "mail", "config", "flair"
. To add a moderator with full permissions, omit this property entirely.Returns:
A Promise that fulfills with this Subreddit when this request is complete
- Type
- Promise
Example
r.getSubreddit('snoowrap').setModeratorPermissions({name: 'actually_an_aardvark', permissions: ['mail']})
-
getWikiPage(title)
Gets a given wiki page on this subreddit.
-
Parameters:
Name Type Description title
string The title of the desired wiki page.
Returns:
An unfetched WikiPage object corresponding to the desired wiki page
- Type
- WikiPage
Example
r.getSubreddit('snoowrap').getWikiPage('index') // => WikiPage { title: 'index', subreddit: Subreddit { display_name: 'snoowrap' } }
-
getWikiPages()
Gets the list of wiki pages on this subreddit.
-
Returns:
An Array containing WikiPage objects
- Type
- Promise
Example
r.getSubreddit('snoowrap').getWikiPages().then(console.log) // => [ // WikiPage { title: 'index', subreddit: Subreddit { display_name: 'snoowrap'} } // WikiPage { title: 'config/sidebar', subreddit: Subreddit { display_name: 'snoowrap'} } // WikiPage { title: 'secret_things', subreddit: Subreddit { display_name: 'snoowrap'} } // WikiPage { title: 'config/submit_text', subreddit: Subreddit { display_name: 'snoowrap'} } // ]
-
getWikiRevisions( [options])
Gets a list of revisions on this subreddit's wiki.
-
Parameters:
Name Type Argument Description options
object <optional>
Options for the resulting Listing
Returns:
A Listing containing wiki revisions
- Type
- Promise
Example
r.getSubreddit('snoowrap').getWikiRevisions().then(console.log) // => Listing [ // { page: 'index', reason: 'added cookies', ... }, // ... // ]
-
fetch()
Fetches this content from reddit.
-
This will not mutate the original content object; all Promise properties will remain as Promises after the content has been fetched. However, the information on this object will be cached, so it may become out-of-date with the content on reddit. To clear the cache and fetch this object from reddit again, use
refresh()
.If snoowrap is running in an environment that supports ES2015 Proxies (e.g. Chrome 49+), then
fetch()
will get automatically called when an unknown property is accessed on an unfetched content object.- Inherited From:
Returns:
A version of this object with all of its fetched properties from reddit. This will not mutate the object. Once an object has been fetched once, its properties will be cached, so they might end up out-of-date if this function is called again. To refresh an object, use refresh().
- Type
- Promise
Example
r.getUser('not_an_aardvark').fetch().then(userInfo => { console.log(userInfo.name); // 'not_an_aardvark' console.log(userInfo.created_utc); // 1419104352 }); r.getComment('d1xchqn').fetch().then(comment => comment.body).then(console.log) // => 'This is a little too interesting for my liking' // In environments that support ES2015 Proxies, the above line is equivalent to: r.getComment('d1xchqn').body.then(console.log); // => 'This is a little too interesting for my liking'
-
refresh()
Refreshes this content.
-
- Inherited From:
Returns:
A newly-fetched version of this content
- Type
- Promise
Example
var someComment = r.getComment('cmfkyus'); var initialCommentBody = some_comment.fetch().then(comment => comment.body); setTimeout(() => { someComment.refresh().then(refreshedComment => { if (initialCommentBody.value() !== refreshedComment.body) { console.log('This comment has changed since 10 seconds ago.'); } }); }, 10000);
-
toJSON()
Returns a stringifyable version of this object.
-
It is usually not necessary to call this method directly; simply running JSON.stringify(some_object) will strip the private properties anyway.
- Inherited From:
Returns:
A version of this object with all the private properties stripped
- Type
- object
Example
var user = r.getUser('not_an_aardvark'); JSON.stringify(user) // => '{"name":"not_an_aardvark"}'