Skip to content

Commit ebebb07

Browse files
authored
feat: infer modal/component callback names from coroutine (#1519)
* feat: infer callback decor from coroutine name * docs: add new logic notation * chore: add doc notation to component callback definition
1 parent 8da4f25 commit ebebb07

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

interactions/models/internal/application_commands.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,14 +1162,18 @@ def component_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable]
11621162
Your callback will be given a single argument, `ComponentContext`
11631163
11641164
Note:
1165-
This can optionally take a regex pattern, which will be used to match against the custom ID of the component
1165+
This can optionally take a regex pattern, which will be used to match against the custom ID of the component.
1166+
1167+
If you do not supply a `custom_id`, the name of the coroutine will be used instead.
11661168
11671169
Args:
11681170
*custom_id: The custom ID of the component to wait for
11691171
11701172
"""
11711173

11721174
def wrapper(func: AsyncCallable) -> ComponentCommand:
1175+
custom_id = custom_id or [func.__name__] # noqa: F823
1176+
11731177
if not asyncio.iscoroutinefunction(func):
11741178
raise ValueError("Commands must be coroutines")
11751179

@@ -1188,14 +1192,18 @@ def modal_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable], Mo
11881192
Your callback will be given a single argument, `ModalContext`
11891193
11901194
Note:
1191-
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal
1195+
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal.
1196+
1197+
If you do not supply a `custom_id`, the name of the coroutine will be used instead.
11921198
11931199
11941200
Args:
11951201
*custom_id: The custom ID of the modal to wait for
11961202
"""
11971203

11981204
def wrapper(func: AsyncCallable) -> ModalCommand:
1205+
custom_id = custom_id or [func.__name__] # noqa: F823
1206+
11991207
if not asyncio.iscoroutinefunction(func):
12001208
raise ValueError("Commands must be coroutines")
12011209

0 commit comments

Comments
 (0)