Skip to content

feat: infer modal/component callback names from coroutine #1519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,14 +1162,18 @@ def component_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable]
Your callback will be given a single argument, `ComponentContext`

Note:
This can optionally take a regex pattern, which will be used to match against the custom ID of the component
This can optionally take a regex pattern, which will be used to match against the custom ID of the component.

If you do not supply a `custom_id`, the name of the coroutine will be used instead.

Args:
*custom_id: The custom ID of the component to wait for

"""

def wrapper(func: AsyncCallable) -> ComponentCommand:
custom_id = custom_id or [func.__name__] # noqa: F823

if not asyncio.iscoroutinefunction(func):
raise ValueError("Commands must be coroutines")

Expand All @@ -1188,14 +1192,18 @@ def modal_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable], Mo
Your callback will be given a single argument, `ModalContext`

Note:
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal.

If you do not supply a `custom_id`, the name of the coroutine will be used instead.


Args:
*custom_id: The custom ID of the modal to wait for
"""

def wrapper(func: AsyncCallable) -> ModalCommand:
custom_id = custom_id or [func.__name__] # noqa: F823

if not asyncio.iscoroutinefunction(func):
raise ValueError("Commands must be coroutines")

Expand Down