Menu
- class asyncpraw.models.Menu(reddit: asyncpraw.Reddit, _data: Dict[str, Any])
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("test") topbar = [widget async for widget in subreddit.widgets.topbar()] if len(topbar) > 0: probably_menu = topbar[0] assert isinstance(probably_menu, asyncpraw.models.Menu) for item in probably_menu: if isinstance(item, asyncpraw.models.Submenu): print(item.text) for child in item: print("\t", child.text, child.url) else: # MenuLink print(item.text, item.url)
Create one:
subreddit = await reddit.subreddit("test") widgets = subreddit.widgets menu_contents = [ {"text": "My homepage", "url": "https://example.com"}, { "text": "Python packages", "children": [ {"text": "asyncpraw", "url": "https://asyncpraw.readthedocs.io/"}, {"text": "requests", "url": "http://python-requests.org"}, ], }, {"text": "Reddit homepage", "url": "https://reddit.com"}, ] menu = await widgets.mod.add_menu(data=menu_contents)
For more information on creation, see
add_menu().Update one:
menu_items = list(menu) menu_items.reverse() menu = await menu.mod.update(data=menu_items)
Delete one:
await menu.mod.delete()
Typical Attributes
Note
This table describes attributes that typically belong to objects of this class. Async PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, Async PRAW makes no effort to document any new/removed/changed attributes, other than to instruct you on how to discover what is available. As a result, this table of attributes may not be complete. See Determine Available Attributes of an Object for detailed information.
If you would like to add an attribute to this table, feel free to open a pull request.
Attribute
Description
dataA list of the
MenuLinks andSubmenus in this widget. Can be iterated over by iterating over theMenu(e.g.,for item in menu).idThe widget ID.
kindThe widget kind (always
"menu").subredditThe
Subredditthe button widget belongs to.- mod() → asyncpraw.models.WidgetModeration
Get an instance of
WidgetModerationfor this widget.Note
Using any of the methods of
WidgetModerationwill likely make outdated the data in theSubredditWidgetsthat this widget belongs to. To remedy this, callrefresh().