discord-interactions.py

from_coroutine

Function

Autocomplete from an async function, with optional caching.

from discord_interactions.slash import from_coroutine

Signature

def from_coroutine(    coro_func: Callable[..., Awaitable[List[str]]],    *,    cache_ttl: float = 0,) -> Callable[..., Awaitable[List[Tuple[str, Any]]]]

Parameters

NameTypeDefaultDescription
coro_funcCallable[..., Awaitable[List[str]]]required
cache_ttlfloat0

Returns

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

Details

Example:

async def fetch_users():    return await db.get_usernames() @slash.command()@autocomplete("user", from_coroutine(fetch_users, cache_ttl=60))async def find_user(ctx, user: str): ...

Type a name: create_button, ModalBuilder, cooldown.