Skip to content

Commit def9017

Browse files
authored
feat: Handle async checks in wait_for_component (#1406)
* fix: Correctly handle async checks in wait_for_component * chore: update typehint
1 parent 2e910ae commit def9017

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

interactions/client/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ async def wait_for_component(
11051105
dict,
11061106
]
11071107
] = None,
1108-
check: Optional[Callable] = None,
1108+
check: Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] = None,
11091109
timeout: Optional[float] = None,
11101110
) -> "events.Component":
11111111
"""
@@ -1136,14 +1136,16 @@ async def wait_for_component(
11361136
if custom_ids and not all(isinstance(x, str) for x in custom_ids):
11371137
custom_ids = [str(i) for i in custom_ids]
11381138

1139-
def _check(event: events.Component) -> bool:
1139+
async def _check(event: events.Component) -> bool:
11401140
ctx: ComponentContext = event.ctx
11411141
# if custom_ids is empty or there is a match
11421142
wanted_message = not message_ids or ctx.message.id in (
11431143
[message_ids] if isinstance(message_ids, int) else message_ids
11441144
)
11451145
wanted_component = not custom_ids or ctx.custom_id in custom_ids
11461146
if wanted_message and wanted_component:
1147+
if asyncio.iscoroutinefunction(check):
1148+
return bool(check is None or await check(event))
11471149
return bool(check is None or check(event))
11481150
return False
11491151

0 commit comments

Comments
 (0)