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 in start(), 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 remove nextcord.ui.Button objects. This was done since it is what is already written in the docstring and is consistent with disable() and enable().
Changes
Moves the call to self.clear() into send_initial_message instead of start 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 call message.edit if message is None.
For consistency and performance, ButtonMenu.disable() and ButtonMenu.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 of ButtonMenuPages 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 of ButtonMenuPages.send_initial_message.
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