discord-interactions.py

conditional

Function

Picks an autocomplete depending on the context.

from discord_interactions.slash import conditional

Signature

def conditional(    condition: Callable[[AutocompleteContext], bool],    if_true: Callable[..., Awaitable[List[Tuple[str, Any]]]],    if_false: Callable[..., Awaitable[List[Tuple[str, Any]]]],) -> Callable[..., Awaitable[List[Tuple[str, Any]]]]

Parameters

NameTypeDefaultDescription
conditionCallable[[AutocompleteContext], bool]required
if_trueCallable[..., Awaitable[List[Tuple[str, Any]]]]required
if_falseCallable[..., Awaitable[List[Tuple[str, Any]]]]required

Returns

Callable[..., Awaitable[List[Tuple[str, Any]]]]

Details

Example:

@slash.command()@autocomplete("channel", conditional(    lambda ctx: ctx.options.get("type") == "voice",    voice_channels_handler,    text_channels_handler,))async def select_channel(ctx, type: str, channel: str): ...

Type a name: create_button, ModalBuilder, cooldown.