robertwayne / dpymenus

Simplified menus for discord.py developers.
https://dpymenus.com/
MIT License
26 stars 4 forks source link

How i can add timeout to ButtonMenu? #43

Closed InspiredImpact closed 3 years ago

InspiredImpact commented 3 years ago

Just i tried

        menu = Paginator(ctx)
        menu.set_timeout(10)
        menu.add_pages([page1, page2, page3, page4])
        await menu.open()

and like this

class Paginator(ButtonMenu):

    async def _cleanup_reactions(self):
        await self.output.delete()

and just nothing happens, but in the second option, the message is deleted when you click on any reaction and an error pops up that "message was not found"

robertwayne commented 3 years ago

_cleanup_reactions is called on every iteration of the menu loop to remove old reactions when the page changes, so what is happening is that the menu will go on to its next iteration and tries accessing the output, which it expects to be there. Timeouts are handled by an internal method in BaseMenu called _execute_timeout, so you can override that if you're looking to change functionality from the default behavior.

That said, the default timeout behavior should 'just work' on anything that inherits from a *Menu class. Is there something specific you are trying to accomplish which isn't working?

InspiredImpact commented 3 years ago

I just set a timeout and it ignores it, so I put it here for 10 seconds and it should have deleted it, but it doesn’t delete it for as long as a minute (despite the fact that I was completely inactive)

        menu = MenuPages(self.ctx).set_timeout(10)
        menu.persist_on_close()
        menu.add_pages([page1, page2, page3, page4])
        await menu.open()

where MenuPages is

class MenuPages(ButtonMenu):
      pass
InspiredImpact commented 3 years ago

In paginatedmenu timeout works, but in buttonmenu - no. if I recreate the function where bot.wait_for and write a timeout there directly, then it will work, but along with this, a bunch of bugs appear.

robertwayne commented 3 years ago

I'm assuming you are, but can you just confirm you're using the latest version 1.3.1?

Previous versions did have a bug with button menu timeouts.

InspiredImpact commented 3 years ago

ohhh yes thank you so much..