Lingo.Component (Lingo v0.4.2)

Copy Markdown View Source

Builders for message components: buttons and select menus. They return the maps Discord expects.

Lingo.Api.Message.create(channel_id, %{
  content: "Pick one",
  components: [
    Lingo.Component.action_row([
      Lingo.Component.button(custom_id: "vote:yes", label: "Yes", style: :success),
      Lingo.Component.button(custom_id: "vote:no", label: "No", style: :danger)
    ])
  ]
})

Clicks reach Lingo.Bot.handle_component/2. Layout components are in Lingo.Component.Layout and modal inputs in Lingo.Component.Modal.

Summary

Functions

A row of up to 5 buttons, or 1 select menu.

A button. Options: :style (:primary, :secondary, :success, :danger, :link or :premium), :custom_id (or :url for links), :label, :emoji, :disabled and :sku_id (for premium buttons).

A select menu of channels. Takes the options of user_select/2, plus :channel_types.

A preselected entry for a user, role, mentionable or channel select: type is :user, :role or :channel.

A select menu of users and roles. Takes the same options as user_select/2.

A select menu of roles. Takes the same options as user_select/2.

One choice in a string_select/2. Options: :description, :emoji and :default.

A select menu of your own choices, built with select_option/3. Options: :options, :placeholder, :min_values, :max_values, :required and :disabled.

A select menu of users. Options: :placeholder, :min_values, :max_values, :default_values (see default_value/2), :required and :disabled.

The message flag that enables components v2 (Lingo.Component.Layout). Put it in :flags.

Functions

action_row(components)

@spec action_row([map()]) :: map()

A row of up to 5 buttons, or 1 select menu.

button(opts)

@spec button(keyword()) :: map()

A button. Options: :style (:primary, :secondary, :success, :danger, :link or :premium), :custom_id (or :url for links), :label, :emoji, :disabled and :sku_id (for premium buttons).

channel_select(custom_id, opts \\ [])

@spec channel_select(
  String.t(),
  keyword()
) :: map()

A select menu of channels. Takes the options of user_select/2, plus :channel_types.

default_value(id, type)

@spec default_value(String.t(), String.t() | atom()) :: map()

A preselected entry for a user, role, mentionable or channel select: type is :user, :role or :channel.

mentionable_select(custom_id, opts \\ [])

@spec mentionable_select(
  String.t(),
  keyword()
) :: map()

A select menu of users and roles. Takes the same options as user_select/2.

role_select(custom_id, opts \\ [])

@spec role_select(
  String.t(),
  keyword()
) :: map()

A select menu of roles. Takes the same options as user_select/2.

select_option(label, value, opts \\ [])

@spec select_option(String.t(), String.t(), keyword()) :: map()

One choice in a string_select/2. Options: :description, :emoji and :default.

string_select(custom_id, opts \\ [])

@spec string_select(
  String.t(),
  keyword()
) :: map()

A select menu of your own choices, built with select_option/3. Options: :options, :placeholder, :min_values, :max_values, :required and :disabled.

user_select(custom_id, opts \\ [])

@spec user_select(
  String.t(),
  keyword()
) :: map()

A select menu of users. Options: :placeholder, :min_values, :max_values, :default_values (see default_value/2), :required and :disabled.

v2_flag()

@spec v2_flag() :: integer()

The message flag that enables components v2 (Lingo.Component.Layout). Put it in :flags.