Skip to content

Components

Component builder functions for messages, modals, and v2 components. All are called on the Lingo module.

Action Row

elixir
Lingo.action_row(components)

Wraps components in an action row. Required for buttons and select menus. Max 5 buttons or 1 select per row.

Buttons

elixir
Lingo.button(opts)
OptionTypeDescription
custom_idstringRequired (except for :link style)
labelstringButton text
styleatom:primary, :secondary, :success, :danger, :link, :premium
emojimap%{name: "fire", id: "123"} or %{name: "fire"} for unicode
urlstringURL for link buttons
disabledbooleanDefault false
elixir
Lingo.button(custom_id: "yes", label: "Confirm", style: :success)
Lingo.button(url: "https://example.com", label: "Visit", style: :link)
Lingo.button(custom_id: "react", emoji: %{name: "thumbsup"}, style: :secondary)

Select Menus

String Select

elixir
Lingo.string_select(custom_id, opts \\ [])
OptionTypeDescription
optionslistList of Lingo.select_option/3
placeholderstringPlaceholder text
min_valuesintegerMinimum selections
max_valuesintegerMaximum selections
disabledbooleanDefault false
elixir
Lingo.string_select("color",
  placeholder: "Pick a color",
  options: [
    Lingo.select_option("Red", "red", description: "Warm"),
    Lingo.select_option("Blue", "blue", emoji: %{name: "blue_circle"})
  ]
)

Auto-Populated Selects

These don't take options. Discord populates them.

elixir
Lingo.user_select(custom_id, opts \\ [])
Lingo.role_select(custom_id, opts \\ [])
Lingo.mentionable_select(custom_id, opts \\ [])
Lingo.channel_select(custom_id, opts \\ [])

All accept placeholder, min_values, max_values, and disabled.

Select Option

elixir
Lingo.select_option(label, value, opts \\ [])
OptionTypeDescription
descriptionstringOption description
emojimapEmoji to display
defaultbooleanPre-selected

Default Value

Pre-populate auto-populated selects:

elixir
Lingo.default_value(id, type)

type is :user, :role, or :channel.

Text Input

elixir
Lingo.text_input(custom_id, label, opts \\ [])
Lingo.text_input(custom_id, opts)
OptionTypeDescription
styleatom:short (default) or :paragraph
min_lengthintegerMinimum length
max_lengthintegerMaximum length
requiredbooleanDefault false
valuestringPre-filled value
placeholderstringPlaceholder text
labelstringLabel (if not passed as second arg)
elixir
Lingo.text_input("name", "Your Name", required: true, max_length: 50)
Lingo.text_input("bio", "About You", style: :paragraph, placeholder: "Tell us about yourself")
elixir
Lingo.modal(custom_id, title, components)

Helper that builds the modal payload. components should be a list of action rows containing text inputs.

elixir
Lingo.modal("feedback", "Feedback Form", [
  Lingo.action_row([
    Lingo.text_input("subject", "Subject", required: true)
  ]),
  Lingo.action_row([
    Lingo.text_input("body", "Details", style: :paragraph)
  ])
])

V2 Message Components

These components require the components_v2 message flag.

Section

elixir
Lingo.section(text_displays, accessory)

A section with text and an optional accessory (thumbnail or button).

Text Display

elixir
Lingo.text_display(content)

A text block inside a section or container.

Thumbnail

elixir
Lingo.thumbnail(url, opts \\ [])
OptionTypeDescription
descriptionstringAlt text
spoilerbooleanBlur the image
elixir
Lingo.media_gallery(items)

items is a list of gallery items.

elixir
Lingo.gallery_item(url, opts \\ [])
OptionTypeDescription
descriptionstringCaption
spoilerbooleanBlur the media

Unfurled Media

elixir
Lingo.unfurled_media(url)

Wraps a URL for use in thumbnails and gallery items.

File

elixir
Lingo.file(url, opts \\ [])
OptionType
spoilerboolean

Separator

elixir
Lingo.separator(opts \\ [])
OptionTypeDescription
dividerbooleanShow a line
spacingatom:small or :large

Container

elixir
Lingo.container(components, opts \\ [])
OptionTypeDescription
colorintegerAccent color
spoilerbooleanBlur contents

Components V2 Flag

elixir
Lingo.components_v2_flag()

Returns the integer flag value to enable v2 components on a message:

elixir
Lingo.send_message(channel_id, %{
  flags: Lingo.components_v2_flag(),
  components: [
    Lingo.container([
      Lingo.text_display("Hello from v2 components!")
    ], color: 0x5865F2)
  ]
})

Label

elixir
Lingo.label(label_text, component, opts \\ [])

File Upload

elixir
Lingo.file_upload(custom_id, opts \\ [])

Radio Group

elixir
Lingo.radio_group(custom_id, options, opts \\ [])

Checkbox Group

elixir
Lingo.checkbox_group(custom_id, options, opts \\ [])

Checkbox

elixir
Lingo.checkbox(custom_id, opts \\ [])