Skip to main content
Buttons are interactive components that users can click.

Button

Represents a UI button.
from discord.ui import Button
import discord

button = Button(label="Click Me", style=discord.ButtonStyle.primary)

Constructor

style
ButtonStyle
default:"ButtonStyle.secondary"
The style of the button.
custom_id
str | None
default:"None"
The ID of the button that gets received during an interaction. Auto-generated if not provided.
url
str | None
default:"None"
The URL this button sends you to. Makes the button a link button.
disabled
bool
default:"False"
Whether the button is disabled or not.
label
str | None
default:"None"
The label of the button. Maximum of 80 characters.
emoji
str | PartialEmoji | None
default:"None"
The emoji of the button, if available.
sku_id
int | None
default:"None"
The ID of the SKU this button refers to (for premium buttons).
row
int | None
default:"None"
The relative row this button belongs to (0-4). Automatic ordering if not provided.
id
int | None
default:"None"
The button’s ID.

Attributes

style
ButtonStyle
The style of the button.
custom_id
str | None
The ID of the button that gets received during an interaction. None for link buttons.
url
str | None
The URL this button sends you to.
disabled
bool
Whether the button is disabled or not.
label
str | None
The label of the button, if available.
emoji
PartialEmoji | None
The emoji of the button, if available.
sku_id
int | None
The ID of the SKU this button refers to.
width
int
The width of the button in the UI layout. Always 1.
row
int | None
The row position of this button (0-4), or None if not explicitly set.

Methods

The callback associated with this button. Override this in subclasses or use the decorator.Parameters:
  • interaction (Interaction): The interaction that triggered this button.
async def callback(self, interaction: discord.Interaction):
    await interaction.response.send_message("Button clicked!")

@button Decorator

A decorator that attaches a button to a component.
@discord.ui.button(label="Click Me", style=discord.ButtonStyle.primary)
async def my_button(self, button: discord.ui.Button, interaction: discord.Interaction):
    await interaction.response.send_message("Clicked!")

Parameters

label
str | None
default:"None"
The label of the button.
custom_id
str | None
default:"None"
The ID of the button. Not recommended to set manually.
style
ButtonStyle
default:"ButtonStyle.secondary"
The style of the button.
disabled
bool
default:"False"
Whether the button is disabled or not.
emoji
str | PartialEmoji | None
default:"None"
The emoji of the button.
row
int | None
default:"None"
The relative row this button belongs to (0-4).
id
int | None
default:"None"
The button’s ID.
Premium and link buttons cannot be created with this decorator. Create a Button object manually instead.

Button Styles

Buttons can have different visual styles:
  • ButtonStyle.primary - Blurple button
  • ButtonStyle.secondary - Grey button
  • ButtonStyle.success - Green button
  • ButtonStyle.danger - Red button
  • ButtonStyle.link - Link button (requires url)
  • ButtonStyle.premium - Premium button (requires sku_id)

Examples

import discord
from discord.ui import View, Button

class MyView(View):
    @discord.ui.button(label="Primary", style=discord.ButtonStyle.primary)
    async def primary_button(self, button: Button, interaction: discord.Interaction):
        await interaction.response.send_message("Primary button clicked!", ephemeral=True)
    
    @discord.ui.button(label="Success", style=discord.ButtonStyle.success)
    async def success_button(self, button: Button, interaction: discord.Interaction):
        await interaction.response.send_message("Success!", ephemeral=True)

view = MyView()
await ctx.send("Click a button:", view=view)

Build docs developers (and LLMs) love