Skip to content

Commit 3ee1561

Browse files
authored
Documentation and return value fixes
1 parent 25b5b3c commit 3ee1561

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

discord/ext/menus/pagination.py

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ class PaginatorButton(discord.ui.Button):
3434
3535
Parameters
3636
----------
37-
3837
button_type: :class:`str`
3938
The type of button being created.
4039
Must be one of ``first``, ``prev``, ``next``, or ``last``.
4140
paginator: :class:`Paginator`
42-
The Paginator class where this button will be used
41+
The paginator class where this button will be used.
4342
"""
4443

4544
def __init__(self, label, emoji, style, disabled, button_type, paginator):
@@ -69,30 +68,30 @@ class Paginator(discord.ui.View):
6968
Attributes
7069
----------
7170
current_page: :class:`int`
72-
Zero-indexed value showing the current page number
71+
A zero-indexed value showing the current page number.
7372
page_count: :class:`int`
74-
Zero-indexed value showing the total number of pages
73+
A zero-indexed value showing the total number of pages.
7574
buttons: Dict[:class:`str`, Dict[:class:`str`, Union[:class:`~PaginatorButton`, :class:`bool`]]]
76-
Dictionary containing the :class:`~PaginatorButton` objects included in this Paginator
75+
A dictionary containing the :class:`~PaginatorButton` objects included in this paginator.
7776
user: Optional[Union[:class:`~discord.User`, :class:`~discord.Member`]]
78-
The user or member that invoked the Paginator.
77+
The user or member that invoked the paginator.
7978
message: Union[:class:`~discord.Message`, :class:`~discord.WebhookMessage`]
80-
The message the Paginator is attached to.
79+
The message the paginator is attached to.
8180
8281
Parameters
8382
----------
8483
pages: Union[List[:class:`str`], List[:class:`discord.Embed`]]
85-
Your list of strings and/or embeds to paginate
84+
The list of strings and/or embeds to paginate.
8685
show_disabled: :class:`bool`
87-
Choose whether or not to show disabled buttons
86+
Whether to show disabled buttons.
8887
show_indicator: :class:`bool`
89-
Choose whether to show the page indicator
88+
Whether to show the page indicator.
9089
author_check: :class:`bool`
91-
Choose whether or not only the original user of the command can change pages
90+
Whether only the original user of the command can change pages.
9291
disable_on_timeout: :class:`bool`
93-
Should the buttons be disabled when the pagintator view times out?
92+
Whether the buttons get disabled when the pagintator view times out.
9493
custom_view: Optional[:class:`discord.ui.View`]
95-
A custom view whose items are appended below the pagination buttons
94+
A custom view whose items are appended below the pagination buttons.
9695
"""
9796

9897
def __init__(
@@ -104,7 +103,7 @@ def __init__(
104103
disable_on_timeout=True,
105104
custom_view: Optional[discord.ui.View] = None,
106105
timeout: Optional[float] = 180.0,
107-
):
106+
) -> None:
108107
super().__init__(timeout=timeout)
109108
self.timeout = timeout
110109
self.pages = pages
@@ -182,7 +181,7 @@ async def on_timeout(self) -> None:
182181
item.disabled = True
183182
await self.message.edit(view=self)
184183

185-
async def goto_page(self, interaction: discord.Interaction, page_number=0):
184+
async def goto_page(self, interaction: discord.Interaction, page_number=0) -> None:
186185
"""Updates the interaction response message to show the specified page number.
187186
188187
Parameters
@@ -195,48 +194,43 @@ async def goto_page(self, interaction: discord.Interaction, page_number=0):
195194
.. note::
196195
197196
Page numbers are zero-indexed when referenced internally, but appear as one-indexed when shown to the user.
198-
199-
Returns
200-
---------
201-
:class:`~Paginator`
202-
The Paginator class
203197
"""
204198
self.update_buttons()
205199
page = self.pages[page_number]
206200
await interaction.response.edit_message(
207201
content=page if isinstance(page, str) else None, embed=page if isinstance(page, discord.Embed) else None, view=self
208202
)
209203

210-
async def interaction_check(self, interaction):
204+
async def interaction_check(self, interaction: discord.Interaction) -> bool:
211205
if self.usercheck:
212206
return self.user == interaction.user
213207
return True
214208

215209
def customize_button(
216210
self, button_name: str = None, button_label: str = None, button_emoji=None, button_style: discord.ButtonStyle = discord.ButtonStyle.gray
217-
) -> Union[PaginatorButton, bool]:
211+
) -> PaginatorButton:
218212
"""Allows you to easily customize the various pagination buttons.
219213
220214
Parameters
221215
----------
222216
button_name: :class:`str`
223-
Name of the button to customize
217+
The name of the button to customize.
224218
Must be one of ``first``, ``prev``, ``next``, or ``last``.
225219
button_label: :class:`str`
226-
Label to display on the button
220+
The label to display on the button.
227221
button_emoji:
228-
Emoji to display on the button
222+
The emoji to display on the button.
229223
button_style: :class:`~discord.ButtonStyle`
230-
ButtonStyle to use for the button
224+
The ButtonStyle to use for the button.
231225
232226
Returns
233227
-------
234228
:class:`~PaginatorButton`
235-
The button that was customized
229+
The button that was customized.
236230
"""
237231

238232
if button_name not in self.buttons.keys():
239-
return False
233+
raise ValueError(f"no button named {button_name} was found in this view.")
240234
button: PaginatorButton = self.buttons[button_name]["object"]
241235
button.label = button_label
242236
button.emoji = button_emoji
@@ -295,7 +289,7 @@ def update_buttons(self) -> Dict:
295289

296290
return self.buttons
297291

298-
async def send(self, messageable: abc.Messageable, ephemeral: bool = False):
292+
async def send(self, messageable: abc.Messageable, ephemeral: bool = False) -> Union[discord.Message, discord.WebhookMessage]:
299293
"""Sends a message with the paginated items.
300294
301295
@@ -309,7 +303,7 @@ async def send(self, messageable: abc.Messageable, ephemeral: bool = False):
309303
Returns
310304
--------
311305
Union[:class:`~discord.Message`, :class:`~discord.WebhookMessage`]
312-
The message that was sent with the Paginator.
306+
The message that was sent with the paginator.
313307
"""
314308

315309
if not isinstance(messageable, abc.Messageable):
@@ -355,7 +349,7 @@ async def respond(self, interaction: discord.Interaction, ephemeral: bool = Fals
355349
Returns
356350
--------
357351
:class:`~discord.Interaction`
358-
The message sent with the paginator
352+
The message sent with the paginator.
359353
"""
360354
page = self.pages[0]
361355
self.user = interaction.user

0 commit comments

Comments
 (0)