Async PRAW
stable

Getting Started

  • Quick Start
  • Installing Async PRAW
  • Authenticating via OAuth
  • Configuring Async PRAW
  • Running Multiple Instances of Async PRAW
  • Logging in Async PRAW
  • Frequently Asked Questions

Code Overview

  • The Reddit Instance
  • Working with Async PRAW’s Models
  • Exceptions in Async PRAW
  • Other Classes
    • Collection
    • CollectionModeration
    • SubredditCollections
    • SubredditCollectionsModeration
    • SubmissionFlair
    • SubredditFlair
    • SubredditFlairTemplates
    • SubredditLinkFlairTemplates
    • SubredditRedditorFlairTemplates
    • LiveContributorRelationship
    • LiveThreadContribution
    • LiveThreadStream
    • LiveUpdateContribution
    • CommentModeration
    • RuleModeration
    • SubmissionModeration
    • SubredditModeration
    • SubredditRulesModeration
    • SubredditWidgetsModeration
    • ThingModerationMixin
    • UserSubredditModeration
    • WidgetModeration
    • WikiPageModeration
    • ContributorRelationship
    • ModeratorRelationship
    • SubredditRelationship
    • SubredditFilters
    • SubredditModerationStream
    • SubredditQuarantine
    • SubredditStream
    • SubredditStylesheet
    • SubredditWidgets
    • SubredditWiki
    • ButtonWidget
    • Calendar
    • CommunityList
    • CustomWidget
    • IDCard
    • ImageWidget
    • Menu
    • ModeratorsWidget
    • PostFlairWidget
    • RulesWidget
    • TextArea
    • Auth
    • Button
    • CalendarConfiguration
    • CommentForest
    • CommentHelper
    • Config
    • DomainListing
    • DraftList
    • Emoji
    • FullnameMixin
    • Hover
    • Image
    • ImageData
    • InboxableMixin
    • InlineGif
    • InlineImage
    • InlineMedia
    • InlineVideo
    • ListingGenerator
    • MenuLink
    • ModAction
    • ModeratedList
    • Modmail
    • ModmailMessage
    • Polls
    • Preferences
    • RedditBase
    • RedditorList
    • RedditorStream
    • RemovalReason
    • Rule
    • Styles
    • Stylesheet
    • SubListing
    • Submenu
    • SubredditEmoji
    • SubredditMessage
    • SubredditRemovalReasons
    • SubredditRules
    • Token Manager
    • Trophy
    • UserSubreddit
    • Util

Tutorials

  • Comment Extraction and Parsing
  • Working with Refresh Tokens
  • Submission Stream Reply Bot

Package Info

  • Change Log
  • Contributing to Async PRAW
  • Glossary
  • Migrating to Async PRAW
  • Migrating to PRAW 7.X
  • References
  • Index
Async PRAW
  • »
  • Other Classes »
  • Menu
  • Edit on GitHub

Menu

class asyncpraw.models.Menu(reddit, _data)

Class to represent the top menu widget of a subreddit.

Menus can generally be found as the first item in a subreddit’s top bar.

subreddit = await reddit.subreddit("redditdev")
topbar = [widget async for widget in subreddit.widgets.topbar()]
if len(topbar) > 0:
    probably_menu = topbar[0]
    assert isinstance(probably_menu, praw.models.Menu)
    for item in probably_menu:
        if isinstance(item, praw.models.Submenu):
            print(item.text)
            for child in item:
                print("\t", child.text, child.url)
        else:  # MenuLink
            print(item.text, item.url)

Create one (requires proper moderator permissions):

subreddit = await reddit.subreddit("redditdev")
widgets = subreddit.widgets
menu_contents = [
    {"text": "My homepage", "url": "https://example.com"},
    {
        "text": "Python packages",
        "children": [
            {"text": "PRAW", "url": "https://praw.readthedocs.io/"},
            {"text": "requests", "url": "http://python-requests.org"},
        ],
    },
    {"text": "Reddit homepage", "url": "https://reddit.com"},
]
menu = await widgets.mod.add_menu(menu_contents)

For more information on creation, see add_menu().

Update one (requires proper moderator permissions):

menu_items = list(menu)
menu_items.reverse()
menu = await menu.mod.update(data=menu_items)

Delete one (requires proper moderator permissions):

await menu.mod.delete()

Typical Attributes

This table describes attributes that typically belong to objects of this class. Since attributes are dynamically provided (see Determine Available Attributes of an Object), there is not a guarantee that these attributes will always be present, nor is this list necessarily complete.

Attribute

Description

data

A list of the MenuLinks and Submenus in this widget. Can be iterated over by iterating over the Menu (e.g. for item in menu).

id

The widget ID.

kind

The widget kind (always "menu").

subreddit

The Subreddit the button widget belongs to.

__contains__(item: Any) → bool

Test if item exists in the list.

__getitem__(index: int) → Any

Return the item at position index in the list.

__init__(reddit, _data)

Initialize an instance of the class.

__iter__() → Iterator[Any]

Return an iterator to the list.

__len__() → int

Return the number of items in the list.

mod()

Get an instance of WidgetModeration for this widget.

Note

Using any of the methods of WidgetModeration will likely make outdated the data in the SubredditWidgets that this widget belongs to. To remedy this, call refresh().

classmethod parse(data: Dict[str, Any], reddit: asyncpraw.Reddit) → Any

Return an instance of cls from data.

Parameters
  • data – The structured data.

  • reddit – An instance of Reddit.

Note

This list of attributes is not complete. Async PRAW dynamically provides the attributes that Reddit returns via the API. Because those attributes are subject to change on Reddit’s end, Async PRAW makes no effort to document them, other than to instruct you on how to discover what is available. See Determine Available Attributes of an Object for detailed information.

Previous Next

© Copyright 2021, Joel Payne. Revision a0108f7c.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: stable
Versions
latest
stable
v7.5.0
v7.4.0
v7.3.1
v7.3.0
v7.2.0
v7.1.1
v7.1.0
Downloads
html
On Read the Docs
Project Home
Builds