SubredditLinkFlairTemplates
- class praw.models.reddit.subreddit.SubredditLinkFlairTemplates(subreddit: praw.models.Subreddit)
Provide functions to interact with link flair templates.
- __init__(subreddit: praw.models.Subreddit)
Initialize a
SubredditFlairTemplates
instance.- Parameters
subreddit – The subreddit whose flair templates to work with.
Note
This class should not be initialized directly. Instead, obtain an instance via:
reddit.subreddit("test").flair.templates
orreddit.subreddit("test").flair.link_templates
.
- __iter__() Generator[Dict[str, Union[str, int, bool, List[Dict[str, str]]]], None, None]
Iterate through the link flair templates as a moderator.
For example:
for template in reddit.subreddit("test").flair.link_templates: print(template)
- add(text: str, *, allowable_content: Optional[str] = None, background_color: Optional[str] = None, css_class: str = '', max_emojis: Optional[int] = None, mod_only: Optional[bool] = None, text_color: Optional[str] = None, text_editable: bool = False)
Add a link flair template to the associated subreddit.
- Parameters
text – The flair template’s text.
allowable_content – If specified, most be one of
"all"
,"emoji"
, or"text"
to restrict content to that type. If set to"emoji"
then the"text"
param must be a valid emoji string, for example,":snoo:"
.background_color – The flair template’s new background color, as a hex color.
css_class – The flair template’s css_class (default:
""
).max_emojis – Maximum emojis in the flair (Reddit defaults this value to
10
).mod_only – Indicate if the flair can only be used by moderators.
text_color – The flair template’s new text color, either
"light"
or"dark"
.text_editable – Indicate if the flair text can be modified for each redditor that sets it (default:
False
).
For example, to add an editable link flair try:
reddit.subreddit("test").flair.templates.add( "PRAW", css_class="praw", text_editable=True, )
- clear()
Remove all link flair templates from the subreddit.
For example:
reddit.subreddit("test").flair.link_templates.clear()
- delete(template_id: str)
Remove a flair template provided by
template_id
.For example, to delete the first
Redditor
flair template listed, try:template_info = list(subreddit.flair.templates)[0] subreddit.flair.templates.delete(template_info["id"])
- static flair_type(is_link: bool) str
Return
"LINK_FLAIR"
or"USER_FLAIR"
depending onis_link
value.
- update(template_id: str, *, allowable_content: Optional[str] = None, background_color: Optional[str] = None, css_class: Optional[str] = None, fetch: bool = True, max_emojis: Optional[int] = None, mod_only: Optional[bool] = None, text: Optional[str] = None, text_color: Optional[str] = None, text_editable: Optional[bool] = None)
Update the flair template provided by
template_id
.- Parameters
template_id – The flair template to update. If not valid then an exception will be thrown.
allowable_content – If specified, most be one of
"all"
,"emoji"
, or"text"
to restrict content to that type. If set to"emoji"
then the"text"
param must be a valid emoji string, for example,":snoo:"
.background_color – The flair template’s new background color, as a hex color.
css_class – The flair template’s new css_class (default:
""
).fetch – Whether PRAW will fetch existing information on the existing flair before updating (default:
True
).max_emojis – Maximum emojis in the flair (Reddit defaults this value to
10
).mod_only – Indicate if the flair can only be used by moderators.
text – The flair template’s new text.
text_color – The flair template’s new text color, either
"light"
or"dark"
.text_editable – Indicate if the flair text can be modified for each redditor that sets it (default:
False
).
Warning
If parameter
fetch
is set toFalse
, all parameters not provided will be reset to their default (None
orFalse
) values.For example, to make a user flair template text editable, try:
template_info = list(subreddit.flair.templates)[0] subreddit.flair.templates.update( template_info["id"], text=template_info["flair_text"], text_editable=True, )