discord-interactions.py

create_button

Function

Creates a button. Values passed in data travel inside the custom_id and come back on click.

from discord_interactions import create_button

Signature

def create_button(    custom_id: str = '',    label: str = '',    style: str | int = 1,    emoji: str | Dict[str, Any] | Any | None = None,    data: Dict[str, Any] | None = None,    disabled: bool = False,    url: str | None = None,    sku_id: int | str | None = None,    component_id: int | None = None,) -> Dict[str, Any]

Parameters

NameTypeDefaultDescription
custom_idstr''Base identifier, sent back on click. Must be unique within the message.
labelstr''Button text (80 characters max).
stylestr | int1Style: a name ("primary", "success", "danger") or a ButtonStyle number.
emojistr | Dict[str, Any] | Any | NoneNoneUnicode emoji, custom emoji "<:name:id>", dict or discord.PartialEmoji.
dataDict[str, Any] | NoneNoneJSON dict embedded in the custom_id (100 characters in total).
disabledboolFalseGreyed out and not clickable.
urlstr | NoneNoneExternal link: the button becomes a Link button.
sku_idint | str | NoneNoneSKU to purchase: the button becomes a Premium button.
component_idint | NoneNoneOptional numeric identifier, unique within the message.

Returns

Dict[str, Any] The button dict (type 2).

Example

from discord_interactions import create_action_row, create_button bouton = create_button(    "acheter",    "Acheter",    style="success",    emoji="<:piece:123456789012345678>",    data={"article": 42},)await ctx.respond("Boutique", components=[create_action_row(bouton)])

Type a name: create_button, ModalBuilder, cooldown.