discord-interactions.py

String

Function

Text option with length, choices, regex and autocomplete.

from discord_interactions import String

Signature

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,) -> StringOption

Parameters

NameTypeDefaultDescription
namestrrequiredOption name (32 characters, lowercase).
descriptionstrrequiredDescription (100 characters).
requiredboolTrueOption required.
defaultAnyNoneValue when the option is omitted.
min_lengthint | NoneNoneMinimum length.
max_lengthint | NoneNoneMaximum length.
choicesList[Choice | Tuple[str, str]] | NoneNoneFixed choices: Choice or (name, value) tuples.
autocompleteCallable[..., Awaitable[List[Tuple[str, Any]]]] | NoneNoneAutocomplete function.
patternstr | NoneNoneRegex checked by the bot.
pattern_errorstr | NoneNoneMessage when the regex fails.
validatorCallable[[str], bool | str] | NoneNoneValidation function: True, False or an error message.
transformerCallable[[str], Any] | NoneNoneFunction applied to the value before the call.
localizationsDict[str, Tuple[str, str]] | NoneNone{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):    ...

Type a name: create_button, ModalBuilder, cooldown.