fix: Clear buttons before sending if one page async iterator source #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
There is a small issue with AsyncIterator page sources where if a menu requires only 1 page, the buttons will be created but then removed within a second. This happens because
is_paginating
is not able to determine if more than 1 page is needed until the first page is read. This will also apply to any custom page sources where the former applies. Currently the buttons are cleared instart()
, after the menu has been sent.This PR makes it so that the buttons are removed from the view after the page is read, but before it is sent so that it doesn't need to be edited afterwards.
Additionally,
ButtonMenu.clear()
was updated to only removenextcord.ui.Button
objects. This was done since it is what is already written in the docstring and is consistent withdisable()
andenable()
.Changes
Moves the call to
self.clear()
intosend_initial_message
instead ofstart
so that with async iterator page source, it will not send the buttons if there is only one page.ButtonMenu.clear()
was fixed to only clear buttons and not all items, and additionally not callmessage.edit
if message isNone
.For consistency and performance,
ButtonMenu.disable()
andButtonMenu.enable()
similarly will not edit the message if the view has not changed.Potentially breaking
ButtonMenu.clear()
will now only clear Buttons. The docstring for this method already said that it would clear Buttons, but the implementation has been changed to make it so that other types of items (eg. select menus) will no longer be removed.If a user is overriding
send_initial_message
in a subclass ofButtonMenuPages
and sends a pagination menu that only requires 1 page, the buttons may no longer be cleared since the clearing now only happens in the default implementation ofButtonMenuPages.send_initial_message
.Gifs
Before
After