diff --git a/README.md b/README.md index c0ea7ce..cc0f49e 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Buttons/button types are used when you want to add a reaction to the menu that d |------|------|---------------|---------- | `name` | `str` |`None` | The name of the button object | `custom_embed` | `discord.Embed` | `None` | When the reaction is pressed, go to the specifed embed. -| `details` | `function` | `None` | Assigns the function and it's arguments to call when a `Button` with `ButtonType.CALLER is pressed` +| `details` | `function` | `None` | Assigns the function and it's arguments to call when a `Button` with `ButtonType.CALLER` is pressed --- ## Button and ButtonType in detail * Associated methods @@ -161,12 +161,13 @@ menu.add_button(close_menu_button) Remove all buttons with `menu.clear_all_buttons()`. You can also remove an individual button using its name if you have it set, or the button object itself with `menu.remove_button()` ##### ButtonType methods -At the moment, there is only 1 method in the `ButtonType` class. Class method `caller_details`. This class method is used to setup functions and it's arguments that are later called when the button is pressed. `ButtonType.CALLER` buttons are used to implement your own functionality into the menu. Maybe you want to add a button that creates a text channel or add something to a database. Please note that functions that are registered as commands (`@client.command()`) are not allowed to be used as a caller button type. Only normal functions can be used with `ButtonType.CALLER` +At the moment, there is only 1 method in the `ButtonType` class. Class method `caller_details`. This class method is used to setup functions and it's arguments that are later called when the button is pressed. `ButtonType.CALLER` buttons are used to implement your own functionality into the menu. Maybe you want to add a button that creates a text channel or add something to a database. >Example ```py -async def add_to_database(name, discord_id, *, country): +@client.command() +async def add_to_database(ctx, name, discord_id, *, country): # . . . def car(make, year): @@ -174,7 +175,7 @@ def car(make, year): menu = ReactionMenu(...) -db_add = Button(emoji='\U000027a1', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(add_to_database, 'Defxult', 123456789, country='U.S')) +db_add = Button(emoji='\U000027a1', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(add_to_database, ctx, 'Defxult', 123456789, country='U.S')) vehicle = Button(emoji='\U000023ea', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(car, 'Ford', 2021)) menu.add_button(db_add) diff --git a/reactionmenu/__init__.py b/reactionmenu/__init__.py index 4339804..3a3d309 100644 --- a/reactionmenu/__init__.py +++ b/reactionmenu/__init__.py @@ -1,2 +1,2 @@ from .core import ReactionMenu, Button, ButtonType -__version__ = '1.0.3' +__version__ = '1.0.4' diff --git a/reactionmenu/core.py b/reactionmenu/core.py index 91cda76..ddb4664 100644 --- a/reactionmenu/core.py +++ b/reactionmenu/core.py @@ -55,7 +55,7 @@ class ButtonType(Enum): @classmethod def caller_details(cls, func, *args, **kwargs) -> tuple: - """Registers the function to call as well as it's arguments. The 'func' parameter should NOT be a function that is a command ( `@client.command()` ) or event ( `@client.event` ). Only plain functions (including async) are to be used + """Registers the function to call as well as it's arguments. Parameter --------- @@ -76,9 +76,11 @@ def holiday(location, season, month, *, moto): ``` .. Added v1.0.3 + + .. Changes :: v1.0.4 + - Support for commands to be used as functions to call """ - if isinstance(func, Command): - raise ReactionMenuException(f'Function {func.callback.__name__!r} cannot be used with ButtonType.CALLER because it is registered as a command. Commands cannot be registered as callers. Only normal functions should be used') + func = func.callback if isinstance(func, Command) else func return (func, args, kwargs) diff --git a/setup.py b/setup.py index 838b03a..c517b1c 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ def _get_readme(): author='Defxult#8269', name='reactionmenu', description='A package to create a discord.py reaction menu. If your discord.py version is 1.5.0+, intents are required', - version='1.0.3', + version='1.0.4', url='https://github.com/Defxult', project_urls=details, classifiers=classifiers,