Skip to content

Button API Reference#

Button #

Button(
    label: str | None = None,
    *,
    emoji: hikari.Emoji | str | None = None,
    style: InteractiveButtonStylesT = hikari.ButtonStyle.PRIMARY,
    disabled: bool = False,
    custom_id: str | None = None,
    row: int | None = None,
    position: int | None = None,
    autodefer: (
        bool | AutodeferOptions | hikari.UndefinedType
    ) = hikari.UNDEFINED
)

Bases: InteractiveViewItem

A view component representing an interactive button.

PARAMETER DESCRIPTION
label

The button's label

TYPE: str | None DEFAULT: None

emoji

The emoji present on the button

TYPE: hikari.Emoji | str | None DEFAULT: None

style

The button's style

TYPE: hikari.ButtonStyle DEFAULT: hikari.ButtonStyle.PRIMARY

disabled

A boolean determining if the button should be disabled or not

TYPE: bool DEFAULT: False

custom_id

The custom identifier of the button

TYPE: str | None DEFAULT: None

row

The row the button should be in, leave as None for auto-placement.

TYPE: int | None DEFAULT: None

position

The position the button should be in within a row, leave as None for auto-placement.

TYPE: int | None DEFAULT: None

autodefer

The autodefer options for the button. If left UNDEFINED, the view's autodefer options will be used.

TYPE: bool | AutodeferOptions | hikari.UndefinedType DEFAULT: hikari.UNDEFINED

RAISES DESCRIPTION
TypeError

If both label and emoji are left empty.

TypeError

if both custom_id and url are provided.

row property writable #

row: int | None

The row the item should occupy. Leave as None for automatic placement.

position property writable #

position: int | None

The position of the item within the row it occupies.

custom_id property writable #

custom_id: str

The item's custom identifier. This will be used to track the item through interactions and is required for persistent views.

width property #

width: int

The item's width taken up in a Discord UI action row.

view property #

view: View

The view this item is attached to.

disabled property writable #

disabled: bool

Indicates whether the item is disabled or not.

autodefer property #

Indicates whether the item should be deferred automatically. If left as UNDEFINED, the view's autodefer option will be used.

type property #

The component's underlying component type.

style property writable #

The button's style.

label property writable #

label: str | None

The button's label. This is the text visible on the button.

emoji property writable #

emoji: hikari.Emoji | None

The emoji that should be visible on the button.

callback async #

callback(context: ViewContext) -> None

The component's callback, gets called when the component receives an interaction.

PARAMETER DESCRIPTION
context

The context, proxying the incoming interaction.

TYPE: ViewContextT

LinkButton #

LinkButton(
    url: str,
    label: str | None = None,
    *,
    emoji: hikari.Emoji | str | None = None,
    disabled: bool = False,
    row: int | None = None,
    position: int | None = None
)

Bases: ViewItem

A view component representing a link button.

PARAMETER DESCRIPTION
url

The URL of the button

TYPE: str | None

label

The button's label

TYPE: str | None DEFAULT: None

emoji

The emoji present on the button

TYPE: hikari.Emoji | str | None DEFAULT: None

disabled

A boolean determining if the button should be disabled or not

TYPE: bool DEFAULT: False

row

The row the button should be in, leave as None for auto-placement.

TYPE: int | None DEFAULT: None

position

The position the button should be in within a row, leave as None for auto-placement.

TYPE: int | None DEFAULT: None

RAISES DESCRIPTION
TypeError

If both label and emoji are left empty.

TypeError

if both custom_id and url are provided.

row property writable #

row: int | None

The row the item should occupy. Leave as None for automatic placement.

position property writable #

position: int | None

The position of the item within the row it occupies.

custom_id property writable #

custom_id: str

The item's custom identifier. This will be used to track the item through interactions and is required for persistent views.

width property #

width: int

The item's width taken up in a Discord UI action row.

view property #

view: View

The view this item is attached to.

disabled property writable #

disabled: bool

Indicates whether the item is disabled or not.

type property #

The component's underlying component type.

style property #

style: t.Literal[hikari.ButtonStyle.LINK]

The button's style.

label property writable #

label: str | None

The button's label. This is the text visible on the button.

emoji property writable #

emoji: hikari.Emoji | None

The emoji that should be visible on the button.

url property writable #

url: str

The URL of the button.

button #

button(
    label: str | None = None,
    *,
    emoji: str | hikari.Emoji | None = None,
    custom_id: str | None = None,
    style: InteractiveButtonStylesT = hikari.ButtonStyle.PRIMARY,
    row: int | None = None,
    disabled: bool = False,
    autodefer: (
        bool | AutodeferOptions | hikari.UndefinedType
    ) = hikari.UNDEFINED
) -> t.Callable[
    [
        t.Callable[
            [ViewT, ViewContext, Button], t.Awaitable[None]
        ]
    ],
    DecoratedItem[ViewT, Button],
]

A decorator to transform a coroutine function into a Discord UI Button's callback. This must be inside a subclass of View.

PARAMETER DESCRIPTION
label

The button's label

TYPE: str | None DEFAULT: None

emoji

The emoji shown on the button

TYPE: str | hikari.Emoji | None DEFAULT: None

custom_id

The button's custom identifier

TYPE: str | None DEFAULT: None

style

The style of the button

TYPE: InteractiveButtonStylesT DEFAULT: hikari.ButtonStyle.PRIMARY

row

The row the button should be in, leave as None for auto-placement.

TYPE: int | None DEFAULT: None

disabled

A boolean determining if the button should be disabled or not

TYPE: bool DEFAULT: False

autodefer

The autodefer options for the button. If left UNDEFINED, the view's autodefer options will be used.

TYPE: bool | AutodeferOptions | hikari.UndefinedType DEFAULT: hikari.UNDEFINED

RETURNS DESCRIPTION
Callable[[Callable[[ViewT, ViewContext, Button], Awaitable[None]]], DecoratedItem[ViewT, Button]]

The decorated callback function.