discord-interactions

discord_slash.component module

discord_slash.component.emoji_to_dict(emoji: Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str]) dict

Converts a default or custom emoji into a partial emoji dict.

Parameters

emoji (Union[discord.Emoji, discord.PartialEmoji, str]) – The emoji to convert.

class discord_slash.component.Component

Bases: object

Base class for components.

to_dict() dict
classmethod from_json(data: dict)
class discord_slash.component.ButtonStyle(value)

Bases: enum.IntEnum

An enumeration.

blue = 1
gray = 2
grey = 2
green = 3
red = 4
URL = 5
class discord_slash.component.Button(*, label: Optional[str] = None, style: int = ButtonStyle.gray, custom_id: Optional[str] = None, url: Optional[str] = None, disabled: bool = False, emoji: Optional[Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str]] = None)

Bases: discord_slash.component.Component

Creates a button component for use with the components field. Must be used within an ActionRow to be used (see ActionRow()).

Note

At least a label or emoji is required for a button. You can have both, but not neither of them.

Parameters
  • style (Union[ButtonStyle, int]) – Style of the button. Refer to ButtonStyle.

  • label (Optional[str]) – The label of the button.

  • emoji (Union[discord.Emoji, discord.PartialEmoji, dict]) – The emoji of the button.

  • custom_id (Optional[str]) – The custom_id of the button. Needed for non-link buttons.

  • url (Optional[str]) – The URL of the button. Needed for link buttons.

  • disabled (bool) – Whether the button is disabled or not. Defaults to False.

Returns

Button

to_dict() dict
property style: int
property label: str
property url: Optional[str]
property custom_id: str
property disabled: bool
property emoji: discord.partial_emoji.PartialEmoji
set_style(value: int)
set_label(value: int)
set_url(value: int)
set_custom_id(value: str)
set_disabled(value: bool)
set_emoji(emoji: Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str])
classmethod from_json(data: dict)
class discord_slash.component.TextInputStyle(value)

Bases: enum.IntEnum

An enumeration.

SHORT = 1
PARAGRAPH = 2
class discord_slash.component.TextInput(*, style: Optional[Union[discord_slash.component.TextInputStyle, int]] = None, custom_id: Optional[str] = None, label: Optional[str] = None, min_length: Optional[int] = None, max_length: Optional[int] = None, required: bool = True, value: Optional[str] = None, placeholder: Optional[str] = None)

Bases: discord_slash.component.Component

Creates a text input component for modal(form). Must be inside an ActionRow to be used (see ActionRow()).

Parameters
  • style (Union[TextInputStyle, int]) – Style of the text input. Refer to TextInputStyle.

  • custom_id (str) – A custom identifier.

  • label (str) – The label of text input.

  • placeholer (str) – Custom placeholder text if nothing is inputted.

  • min_length (int) – The minimum input length for a text input.

  • max_length (int) – The maximum input length for a text input.

  • value (str) – A pre-filled value.

Returns

TextInput

property custom_id
property style
property label
property min_length
property max_length
property required
property value
property placeholder
to_dict() dict
classmethod from_json(data: dict)
class discord_slash.component.Modal(*, custom_id: Optional[str] = None, title: Optional[str] = None, components: Optional[List[discord_slash.component.TextInput]] = None)

Bases: discord_slash.component.Component

Creates a popup modal(form).

Parameters
  • custom_id (str) – A custom identifier.

  • title (str) – The title of popup modal.

  • components (List[TextInput]) – Between 1 and 5 (inclusive) components that make up the modal.

Returns

Modal

to_dict() dict
class discord_slash.component.Select(*, options: List[discord_slash.component.SelectOption], custom_id: Optional[str] = None, placeholder: Optional[str] = None, min_values: int = 1, max_values: int = 1, disabled: bool = False)

Bases: discord_slash.component.Component

Creates a select (dropdown) component for use with the components field. Must be inside an ActionRow to be used (see ActionRow()).

Parameters
  • options (List[SelectOption]) – The choices the user can pick from.

  • custom_id (str) – A custom identifier, like buttons.

  • placeholder (str) – Custom placeholder text if nothing is selected.

  • min_values (int) – The minimum number of items that must be chosen.

  • max_values (int) – The maximum number of items that can be chosen.

  • disabled (bool) – Disables this component. Defaults to False.

Returns

Select

to_dict() dict
property custom_id: str
property options: List[discord_slash.component.SelectOption]
property placeholder: str
property min_values: int
property max_values: int
property disabled: bool
set_custom_id(value: str)
set_options(value: List[discord_slash.component.SelectOption])
set_placeholder(value: str)
set_min_values(value: int)
set_max_values(value: int)
set_disabled(value: bool)
classmethod from_json(data: dict)
class discord_slash.component.SelectOption(*, label: str, value: str, emoji: Optional[Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str]] = None, description: Optional[str] = None, default: bool = False)

Bases: discord_slash.component.Component

Creates an option for Select components.

Parameters
  • label (str) – The user-facing name of the option that will be displayed in discord client.

  • value (str) – The value that the bot will receive when this option is selected.

  • emoji (Union[Emoji, PartialEmoji, str]) – The emoji of the option.

  • description (str) – An additional description of the option.

  • default (bool) – Whether or not this is the default option.

Returns

SelectOption

to_dict() dict
property label: str
property value: str
property emoji: Optional[discord.partial_emoji.PartialEmoji]
property description: str
property default: bool
set_label(value: str)
set_value(value: str)
set_emoji(emoji: Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str])
set_description(value: str)
set_default(value: bool)
classmethod from_json(data: dict)
class discord_slash.component.ActionRow(*args: List[discord_slash.component.Component])

Bases: discord_slash.component.Component

ActionRow for message components.

Parameters

components – Components to go within the ActionRow.

Returns

ActionRow

disable_components() List[discord_slash.component.Component]
to_dict() dict
append(component: discord_slash.component.Component)
property components: List[discord_slash.component.Component]
set_components(value: List[discord_slash.component.Component])
add_component(value: discord_slash.component.Component)
remove_component(value: discord_slash.component.Component)
classmethod from_json(data: dict)