Skip to content

Commit b9dfe39

Browse files
committed
better method for copying children
1 parent c7f037c commit b9dfe39

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

discord/ext/pages/pagination.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222
DEALINGS IN THE SOFTWARE.
2323
"""
24-
import copy
2524
from typing import Dict, List, Optional, Union
2625

2726
import discord
@@ -274,7 +273,6 @@ def __init__(
274273
self.default_button_row = default_button_row
275274
self.loop_pages = loop_pages
276275
self.custom_view = custom_view
277-
self.custom_view_items = []
278276
self.message: Union[discord.Message, discord.WebhookMessage, None] = None
279277

280278
if self.custom_buttons and not self.use_default_buttons:
@@ -395,6 +393,7 @@ async def disable(
395393
page: Optional[Union[:class:`str`, Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
396394
The page content to show after disabling the paginator.
397395
"""
396+
page = self.get_page_content(page)
398397
for item in self.children:
399398
if item not in self.custom_view_items or include_custom:
400399
item.disabled = True
@@ -421,9 +420,10 @@ async def cancel(
421420
page: Optional[Union[:class:`str`, Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
422421
The page content to show after canceling the paginator.
423422
"""
424-
items = copy.copy(self.children)
423+
items = self.children.copy()
424+
page = self.get_page_content(page)
425425
for item in items:
426-
if item not in self.custom_view_items or include_custom:
426+
if item not in self.custom_view.children or include_custom:
427427
self.remove_item(item)
428428
if page:
429429
await self.message.edit(
@@ -613,9 +613,7 @@ def update_buttons(self) -> Dict:
613613
# The bot developer should handle row assignments for their view before passing it to Paginator
614614
if self.custom_view:
615615
for item in self.custom_view.children:
616-
self.custom_view_items.append(item)
617616
self.add_item(item)
618-
619617
return self.buttons
620618

621619
@staticmethod

examples/views/paginator.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,26 @@ async def pagetest_custom_view(self, ctx: discord.ApplicationContext):
182182
paginator = pages.Paginator(pages=self.get_pages(), custom_view=view)
183183
await paginator.respond(ctx.interaction, ephemeral=False)
184184

185+
@pagetest.command(name="disable")
186+
async def pagetest_disable(self, ctx: discord.ApplicationContext):
187+
"""Demonstrates disabling the paginator buttons and showing a custom page when disabled."""
188+
paginator = pages.Paginator(pages=self.get_pages())
189+
await paginator.respond(ctx.interaction, ephemeral=False)
190+
await ctx.respond("Disabling paginator in 5 seconds...")
191+
await asyncio.sleep(5)
192+
disable_page = discord.Embed(title="Paginator Disabled!", description="This page is only shown when the paginator is disabled.")
193+
await paginator.disable(page=disable_page)
194+
195+
@pagetest.command(name="cancel")
196+
async def pagetest_cancel(self, ctx: discord.ApplicationContext):
197+
"""Demonstrates canceling (stopping) the paginator and showing a custom page when cancelled."""
198+
paginator = pages.Paginator(pages=self.get_pages())
199+
await paginator.respond(ctx.interaction, ephemeral=False)
200+
await ctx.respond("Canceling paginator in 5 seconds...")
201+
await asyncio.sleep(5)
202+
cancel_page = discord.Embed(title="Paginator Cancelled!", description="This page is only shown when the paginator is cancelled.")
203+
await paginator.cancel(page=cancel_page)
204+
185205
@pagetest.command(name="groups")
186206
async def pagetest_groups(self, ctx: discord.ApplicationContext):
187207
"""Demonstrates using page groups to switch between different sets of pages."""

0 commit comments

Comments
 (0)