Menu¶
-
class
praw.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.
topbar = reddit.subreddit("redditdev").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):
widgets = reddit.subreddit("redditdev").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 = 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 = menu.mod.update(data=menu_items)
Delete one (requires proper moderator permissions):
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
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.-
__init__(reddit, _data)¶ Initialize an instance of the class.
-
__iter__() → Iterator[Any]¶ Return an iterator to the list.
-
mod()¶ Get an instance of
WidgetModerationfor this widget.Note
Using any of the methods of
WidgetModerationwill likely make the data in theSubredditWidgetsthat this widget belongs to outdated. To remedy this, callrefresh().
-