|
14 | 14 | # consistency with the `nextcord` namespaced logging
|
15 | 15 | log = logging.getLogger(__name__)
|
16 | 16 |
|
| 17 | +DEFAULT_TIMEOUT = 180.0 |
17 | 18 |
|
18 | 19 | class MenuError(Exception):
|
19 | 20 | pass
|
@@ -312,7 +313,7 @@ class Menu(metaclass=_MenuMeta):
|
312 | 313 | calling :meth:`send_initial_message`\, if for example you have a pre-existing
|
313 | 314 | message you want to attach a menu to.
|
314 | 315 | """
|
315 |
| - def __init__(self, *, timeout=180.0, delete_message_after=False, |
| 316 | + def __init__(self, *, timeout=DEFAULT_TIMEOUT, delete_message_after=False, |
316 | 317 | clear_reactions_after=False, check_embeds=False, message=None):
|
317 | 318 |
|
318 | 319 | self.timeout = timeout
|
@@ -763,6 +764,30 @@ def stop(self):
|
763 | 764 | self.__tasks.clear()
|
764 | 765 |
|
765 | 766 |
|
| 767 | +class ButtonMenu(Menu, nextcord.ui.View): |
| 768 | + r"""An interface that allows handling menus by using button interaction components. |
| 769 | +
|
| 770 | + Buttons should be marked with the :func:`nextcord.ui.button` decorator. Please note that |
| 771 | + this expects the methods to have two parameters, the ``button`` and the ``interaction``. |
| 772 | + The ``button`` is of type :class:`nextcord.ui.Button`. |
| 773 | + The ``interaction`` is of type :class:`nextcord.Interaction`. |
| 774 | + """ |
| 775 | + def __init__(self, timeout=DEFAULT_TIMEOUT, *args, **kwargs): |
| 776 | + Menu.__init__(self, timeout=timeout, *args, **kwargs) |
| 777 | + nextcord.ui.View.__init__(self, timeout=timeout) |
| 778 | + |
| 779 | + async def stop(self): |
| 780 | + """Stops the internal loop and view interactions.""" |
| 781 | + # disable the buttons |
| 782 | + for child in self.children: |
| 783 | + child.disabled = True |
| 784 | + await self.message.edit(view=self) |
| 785 | + # stop the menu loop |
| 786 | + Menu.stop(self) |
| 787 | + # stop view interactions |
| 788 | + nextcord.ui.View.stop(self) |
| 789 | + |
| 790 | + |
766 | 791 | class PageSource:
|
767 | 792 | """An interface representing a menu page's data source for the actual menu page.
|
768 | 793 |
|
@@ -1082,7 +1107,7 @@ class ButtonMenuPages(MenuPagesBase, nextcord.ui.View):
|
1082 | 1107 | The current page that we are in. Zero-indexed
|
1083 | 1108 | between [0, :attr:`PageSource.max_pages`).
|
1084 | 1109 | """
|
1085 |
| - def __init__(self, source, timeout = 180.0, **kwargs): |
| 1110 | + def __init__(self, source, timeout=DEFAULT_TIMEOUT, **kwargs): |
1086 | 1111 | MenuPagesBase.__init__(self, source, **kwargs)
|
1087 | 1112 | nextcord.ui.View.__init__(self, timeout=timeout)
|
1088 | 1113 | skip_double_triangle_buttons = self._skip_double_triangle_buttons()
|
|
0 commit comments