From 792eb112bb2a17aa09c0bf530287b229d1980ed9 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 12 Dec 2021 05:27:52 +0200 Subject: [PATCH] fix: AsyncIterator buttons not getting displayed (#25) --- nextcord/ext/menus/__init__.py | 2 +- nextcord/ext/menus/menu_pages.py | 3 +++ nextcord/ext/menus/page_source.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nextcord/ext/menus/__init__.py b/nextcord/ext/menus/__init__.py index a46e59f..0fc7b60 100644 --- a/nextcord/ext/menus/__init__.py +++ b/nextcord/ext/menus/__init__.py @@ -6,4 +6,4 @@ from .utils import * # Needed for the setup.py script -__version__ = "1.3.3" +__version__ = "1.3.4" diff --git a/nextcord/ext/menus/menu_pages.py b/nextcord/ext/menus/menu_pages.py index 838b478..e4456ff 100644 --- a/nextcord/ext/menus/menu_pages.py +++ b/nextcord/ext/menus/menu_pages.py @@ -121,6 +121,9 @@ async def start( ): await self._source._prepare_once() await super().start(ctx, channel=channel, wait=wait) + # If we're not paginating, we can remove the pagination buttons + if not self._source.is_paginating(): + await self.clear() async def show_checked_page(self, page_number: int): max_pages = self._source.get_max_pages() diff --git a/nextcord/ext/menus/page_source.py b/nextcord/ext/menus/page_source.py index 708c990..f9cd896 100644 --- a/nextcord/ext/menus/page_source.py +++ b/nextcord/ext/menus/page_source.py @@ -339,7 +339,10 @@ async def prepare(self, *, _aiter=_aiter): def is_paginating(self) -> bool: """:class:`bool`: Whether pagination is required.""" - return len(self._cache) > self.per_page + # If we have not prepared yet, we do not know if we are paginating, so we return True + # This is to ensure that the buttons will be created in the case we are paginating + # If we have prepared, but we are exhausted before 1 page, we are not paginating + return not self._cache or len(self._cache) > self.per_page async def _get_single_page(self, page_number: int) -> DataType: if page_number < 0: