String
Function
Text option with length, choices, regex and autocomplete.
from discord_interactions import StringSignature
def String( name: str, description: str, *, required: bool = True, default: Any = None, min_length: int | None = None, max_length: int | None = None, choices: List[Choice | Tuple[str, str]] | None = None, autocomplete: Callable[..., Awaitable[List[Tuple[str, Any]]]] | None = None, pattern: str | None = None, pattern_error: str | None = None, validator: Callable[[str], bool | str] | None = None, transformer: Callable[[str], Any] | None = None, localizations: Dict[str, Tuple[str, str]] | None = None,) -> StringOptionParameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | required | Option name (32 characters, lowercase). |
description | str | required | Description (100 characters). |
required | bool | True | Option required. |
default | Any | None | Value when the option is omitted. |
min_length | int | None | None | Minimum length. |
max_length | int | None | None | Maximum length. |
choices | List[Choice | Tuple[str, str]] | None | None | Fixed choices: Choice or (name, value) tuples. |
autocomplete | Callable[..., Awaitable[List[Tuple[str, Any]]]] | None | None | Autocomplete function. |
pattern | str | None | None | Regex checked by the bot. |
pattern_error | str | None | None | Message when the regex fails. |
validator | Callable[[str], bool | str] | None | None | Validation function: True, False or an error message. |
transformer | Callable[[str], Any] | None | None | Function applied to the value before the call. |
localizations | Dict[str, Tuple[str, str]] | None | None | {locale: (name, description)}. |
Returns
StringOption
Example
from discord_interactions.slash import String, from_list, option @slash.command(description="Couleur")@option(String("hex", "Code couleur", pattern=r"^#[0-9A-Fa-f]{6}$", pattern_error="Format #RRGGBB"))@option(String("nom", "Nom", autocomplete=from_list(["Rouge", "Vert", "Bleu"])))async def couleur(ctx, hex, nom): ...