@@ -58,26 +58,45 @@ Instantiation is the same as for :ref:`Reaction Menus <ext_menus_reaction_menus>
5858
5959.. code :: py
6060
61- await MyButtonMenu().start(ctx)
61+ @bot.command ()
62+ async def menu_example (ctx ):
63+ await MyButtonMenu().start(ctx)
6264
6365 .. _pagination-1 :
6466
6567Pagination
6668~~~~~~~~~~
6769
68- A :class: `ButtonMenuPages ` class is provided for pagination with button
69- components.
70+ A :class: `ButtonMenuPages ` class is provided for pagination with button components.
7071
71- :class: `ButtonMenuPages ` works the same way as :class: `MenuPages `, but with :class: `Button <nextcord.ui.Button> ` components instead of reactions.
72+ :class: `ButtonMenuPages ` works the same way as :class: `MenuPages `, but with
73+ :class: `Button <nextcord.ui.Button> ` components instead of reactions.
7274
73- A :class: `nextcord.ButtonStyle ` can optionally be passed in to customize the
74- appearance of the buttons.
75+ A :class: `nextcord.ButtonStyle ` can optionally be passed in to customize the appearance of the buttons.
7576
76- ``MySource `` is the same as :ref: `defined earlier <MySource >`, but the menu is instantiated
77- with:
77+ The :class: `PageSource ` deals with the data representation and formatting of the data we want to paginate.
78+
79+ ``MySource `` is the same as :ref: `defined earlier <MySource >`, but the menu is instantiated with
80+ :class: `ButtonMenuPages ` as follows:
7881
7982.. code :: py
8083
81- pages = menus.ButtonMenuPages(source = MySource(range (1 , 100 )), clear_buttons_after = True ,
82- style = nextcord.ButtonStyle.primary)
83- await pages.start(ctx)
84+ from nextcord.ext import menus
85+
86+ class MySource (menus .ListPageSource ):
87+ def __init__ (self , data ):
88+ super ().__init__ (data, per_page = 4 )
89+
90+ async def format_page (self , menu , entries ):
91+ offset = menu.current_page * self .per_page
92+ return ' \n ' .join(f ' { i} . { v} ' for i, v in enumerate (entries, start = offset))
93+
94+ @bot.command ()
95+ async def pages_example (ctx ):
96+ data = [" A" , " B" , " C" , " D" , " E" , " F" , " G" , " H" , " I" , " J" ]
97+ pages = menus.ButtonMenuPages(
98+ source = MySource(data),
99+ clear_buttons_after = True ,
100+ style = nextcord.ButtonStyle.primary,
101+ )
102+ await pages.start(ctx)
0 commit comments