discord-interactions.py

build_signed_custom_id

Function

custom_id signed with HMAC-SHA256, with optional expiry. Cannot be forged without the secret.

from discord_interactions import build_signed_custom_id

Signature

def build_signed_custom_id(    base_id: str,    data: Dict[str, Any] | None,    secret: str,    ttl_seconds: int | None = None,    max_length: int = 100,) -> str

Parameters

NameTypeDefaultDescription
base_idstrrequired
dataDict[str, Any] | Nonerequired
secretstrrequiredThe bot's secret key.
ttl_secondsint | NoneNoneValidity in seconds.
max_lengthint100

Returns

str

Example

from discord_interactions import build_signed_custom_id, parse_signed_custom_id custom_id = build_signed_custom_id("retrait", {"montant": 500}, secret=SECRET, ttl_seconds=120)base_id, data, valide, raison = parse_signed_custom_id(custom_id, SECRET)

Type a name: create_button, ModalBuilder, cooldown.