Skip to content

Commit 7513d4d

Browse files
authored
docs: Added more details to docs examples (#23)
1 parent fde38c1 commit 7513d4d

File tree

12 files changed

+236
-58
lines changed

12 files changed

+236
-58
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2021 The Nextcord Developers
4-
Copyright (c) 2015-2020 Danny Y. (Rapptz)
4+
Copyright (c) 2020-2021 Danny Y. (Rapptz)
55

66
Permission is hereby granted, free of charge, to any person obtaining a
77
copy of this software and associated documentation files (the "Software"),

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ py -3 -m pip install -U nextcord-ext-menus
3535
## License
3636

3737
Copyright (c) 2021 The Nextcord Developers
38-
Copyright (c) 2015-2020 Danny Y. (Rapptz)
38+
Copyright (c) 2020-2021 Danny Y. (Rapptz)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
project = "nextcord-ext-menus"
7-
copyright = "2021-present, Nextcord. 2020-2021, Danny (Rapptz)"
7+
copyright = "2021 Nextcord. 2020-2021 Danny (Rapptz)"
88
author = "Nextcord"
99

1010
sys.path.insert(0, os.path.abspath(".."))

docs/ext/menus/button_menus.rst

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6567
Pagination
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)

docs/ext/menus/menu_examples.rst

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@ For pagination examples, see :ref:`ext_menus_pagination_examples`.
1212

1313
.. contents::
1414

15+
Reaction Menus
16+
--------------
17+
1518
Basic Reaction Menu
16-
-------------------
19+
~~~~~~~~~~~~~~~~~~~
20+
21+
This example shows how to make a reaction menu with three buttons.
22+
23+
All reaction menus are created by subclassing :class:`Menu`.
24+
25+
Reactions are added to the menu using the :func:`button` decorator.
26+
27+
To start the menu, call :meth:`start() <Menu.start>` on the menu, passing
28+
:class:`Context <nextcord.ext.commands.Context>`.
1729

1830
.. code:: py
1931
20-
import nextcord
2132
from nextcord.ext import commands, menus
2233
2334
bot = commands.Bot(command_prefix="$")
@@ -45,7 +56,11 @@ Basic Reaction Menu
4556
bot.run('token')
4657
4758
Wait for Confirmation
48-
---------------------
59+
~~~~~~~~~~~~~~~~~~~~~
60+
61+
In this example, we make a reaction menu that waits for a confirmation from the user.
62+
63+
We do this by using the ``wait=True`` argument to :meth:`start() <Menu.start>`.
4964

5065
.. code:: py
5166
@@ -78,8 +93,21 @@ Wait for Confirmation
7893
if confirm:
7994
await ctx.send('deleted...')
8095
96+
Button Menus
97+
------------
98+
8199
Basic Button Menu
82-
-----------------
100+
~~~~~~~~~~~~~~~~~
101+
102+
This example shows how to make a button menu like the reaction version shown above.
103+
104+
To use buttons instead of reactions, we will use :class:`ButtonMenu` instead of :class:`Menu`
105+
and :func:`nextcord.ui.button` instead of the :func:`menus.button() <button>` decorator.
106+
107+
We also need to pass ``view=self`` in the initial message for the buttons to appear.
108+
109+
To start the menu, call :meth:`start() <ButtonMenu.start>` on the menu, passing
110+
:class:`Context <nextcord.ext.commands.Context>`.
83111

84112
.. code:: py
85113
@@ -107,7 +135,12 @@ Basic Button Menu
107135
await MyButtonMenu().start(ctx)
108136
109137
Button Confirm
110-
--------------
138+
~~~~~~~~~~~~~~
139+
140+
In this example, we make a button menu that waits for a confirmation from the user.
141+
142+
We use the ``wait=True`` argument to :meth:`start() <ButtonMenu.start>` and create
143+
the :class:`ButtonMenu` in the same way as shown before.
111144

112145
.. code:: py
113146
@@ -135,6 +168,6 @@ Button Confirm
135168
return self.result
136169
137170
@bot.command()
138-
async def button_confirm(ctx: commands.Context):
171+
async def button_confirm(ctx):
139172
confirm = await ButtonConfirm("Confirm?").prompt(ctx)
140173
await ctx.send(f"You said: {confirm}")

0 commit comments

Comments
 (0)