SubredditFlair¶
- class praw.models.reddit.subreddit.SubredditFlair(subreddit)¶
Provide a set of functions to interact with a
Subreddit’s flair.- Parameters:
subreddit (models.Subreddit)
- __call__(redditor=None, **generator_kwargs)¶
Return a
ListingGeneratorfor Redditors and their flairs.- Parameters:
- Return type:
Additional keyword arguments are passed in the initialization of
ListingGenerator.Usage:
for flair in reddit.subreddit("test").flair(limit=None): print(flair)
- __init__(subreddit)¶
Initialize a
SubredditFlairinstance.- Parameters:
subreddit (
Subreddit) – The subreddit whose flair to work with.- Return type:
None
- configure(*, link_position='left', link_self_assign=False, position='right', self_assign=False, **settings)¶
Update the
Subreddit’s flair configuration.- Parameters:
link_position (
str) – One of"left","right", orFalseto disable (default:"left").link_self_assign (
bool) – Permit self assignment of link flair (default:False).position (
str) – One of"left","right", orFalseto disable (default:"right").self_assign (
bool) – Permit self assignment of user flair (default:False).settings (Any)
- Return type:
subreddit = reddit.subreddit("test") subreddit.flair.configure(link_position="right", self_assign=True)
Additional keyword arguments can be provided to handle new settings as Reddit introduces them.
- delete(redditor)¶
Delete flair for a
Redditor.See also
update()to delete the flair of many redditors at once.
- delete_all()¶
- link_templates()¶
Provide an instance of
SubredditLinkFlairTemplates.Use this attribute for interacting with a
Subreddit’s link flair templates. For example to list all the link flair templates for a subreddit which you have theflairmoderator permission on try:for template in reddit.subreddit("test").flair.link_templates: print(template)
- Return type:
- set(redditor, *, css_class='', flair_template_id=None, text='')¶
Set flair for a
Redditor.- Parameters:
redditor (
Redditor|str) – A redditor name orRedditorinstance.text (
str) – The flair text to associate with theRedditororSubmission(default:"").css_class (
str) – The css class to associate with the flair html (default:""). Use either this orflair_template_id.flair_template_id (
str|None) – The ID of the flair template to be used (default:None). Use either this orcss_class.
- Return type:
This method can only be used by an authenticated user who is a moderator of the associated
Subreddit.For example:
reddit.subreddit("test").flair.set("bboe", text="PRAW author", css_class="mods") template = "6bd28436-1aa7-11e9-9902-0e05ab0fad46" reddit.subreddit("test").flair.set( "spez", text="Reddit CEO", flair_template_id=template )
- templates()¶
Provide an instance of
SubredditRedditorFlairTemplates.Use this attribute for interacting with a
Subreddit’s flair templates. For example to list all the flair templates for a subreddit which you have theflairmoderator permission on try:for template in reddit.subreddit("test").flair.templates: print(template)
- Return type:
- update(flair_list, *, text='', css_class='')¶
Set or clear the flair for many redditors at once.
- Parameters:
flair_list (
Iterator[str|Redditor|dict[str,str|Redditor]]) –Each item in this list should be either:
The name of a redditor.
An instance of
Redditor.A dictionary mapping keys
"user","flair_text", and"flair_css_class"to their respective values. The"user"key should map to a redditor, as described above. When a dictionary isn’t provided, or the dictionary is missing either"flair_text"or"flair_css_class"keys, the default values will come from the other arguments.
css_class (
str) – The css class to use when not explicitly provided inflair_list(default:"").text (
str) – The flair text to use when not explicitly provided inflair_list(default:"").
- Return type:
- Returns:
List of dictionaries indicating the success or failure of each update.
For example, to clear the flair text, and set the
"praw"flair css class on a few users try:subreddit.flair.update(["bboe", "spez", "spladug"], css_class="praw")