SubredditRemovalReasons¶
- class asyncpraw.models.reddit.removal_reasons.SubredditRemovalReasons(subreddit)¶
Provide a set of functions to a
Subreddit’s removal reasons.- Parameters:
subreddit (asyncpraw.models.Subreddit)
- __init__(subreddit)¶
Initialize a
SubredditRemovalReasonsinstance.- Parameters:
subreddit (
Subreddit) – The subreddit whose removal reasons to work with.- Return type:
None
- await add(*, message, title)¶
Add a removal reason to this subreddit.
- Parameters:
- Return type:
- Returns:
The
RemovalReasonadded.
The message will be prepended with
Hi u/username,automatically.To add
"Test"to r/test try:subreddit = await reddit.subreddit("test") await subreddit.mod.removal_reasons.add(title="Test", message="Foobar")
- await get_reason(id, *, fetch=True)¶
Return the Removal Reason with the ID/number/slice
id.- Parameters:
id (
SupportsIndex) – The ID or index of the removal reason.fetch (
bool) – Determines if Async PRAW will fetch the object (default:True).
- Return type:
This method is to be used to fetch a specific removal reason, like so:
reason_id = "141vv5c16py7d" subreddit = await reddit.subreddit("test") reason = await subreddit.mod.removal_reasons.get_reason(reason_id) print(reason)
You can also use indices to get a numbered removal reason. Since Python uses 0-indexing, the first removal reason is index 0, and so on.
Note
Both negative indices and slices can be used to interact with the removal reasons.
- Raises:
IndexErrorif a removal reason of a specific number does not exist.- Parameters:
id (SupportsIndex)
fetch (bool)
- Return type:
For example, to get the second removal reason of r/test:
subreddit = await reddit.subreddit("test") await subreddit.mod.removal_reasons.get_reason(1)
To get the last three removal reasons in a subreddit:
subreddit = await reddit.subreddit("test") reasons = await subreddit.mod.removal_reasons.get_reason(slice(-3, None)) for reason in reasons: print(reason)
If you don’t need the object fetched right away (e.g., to utilize a class method) you can do:
reason_id = "141vv5c16py7d" subreddit = await reddit.subreddit("test") reason = await subreddit.mod.removal_reasons.get_reason(reason_id, fetch=False) await reason.delete()