An interaction your bot is handling: a slash or context menu command, a component click, a modal submission or an autocomplete request.
Every interaction callback in Lingo.Bot receives one, and this module's
functions are imported into modules that use Lingo.Bot.
Responding
Discord expects an answer within 3 seconds: reply/2, update/2,
show_modal/2 or autocomplete_result/2, or defer/2 first to answer
within 15 minutes. Each returns {:ok, ctx}, remembering that the
interaction was answered so the next reply/2 sends a follow-up. The !
versions return the context or raise Lingo.Error.
def handle_command("slow", ctx) do
ctx = defer!(ctx)
reply!(ctx, "Done: #{do_slow_work()}")
endA context remembers which bot it belongs to, so it can be answered from any process.
Reading input
Options you declared with Lingo.Bot.Commands.command/3 have atom keys and
subcommands nest; modal fields are keyed by their custom id, as strings.
option/2 and modal_value/2 accept either form.
Summary
Functions
Answers autocomplete with up to 25 choices, maps or keyword lists with :name and :value.
Like autocomplete_result/2, but returns the context or raises Lingo.Error.
Acknowledges the interaction now and answers later. Does nothing if
already deferred. Options: :ephemeral (only the user sees the answer) and
:update (for components: the answer edits their message).
Like defer/2, but returns the context or raises Lingo.Error.
Deletes the response message.
Like delete_reply/1, but returns the context or raises Lingo.Error.
Sends a response only the user who triggered the interaction can see.
Like ephemeral/2, but returns the context or raises Lingo.Error.
The option the user is typing in, during autocomplete, as {name, value}.
The attachment an option points at.
The channel an option points at.
The guild member an option points at.
Fetches the response message: the first reply/2 or its edits, not
follow-ups. Use its id with Lingo.Collector.await_component/2.
The role an option points at.
The user an option points at.
Launches the app's Activity, for entry point commands with the :app_handler handler.
Like launch_activity/1, but returns the context or raises Lingo.Error.
The value of a modal field, by its custom id. Same as option/2.
The value of a command option or modal field, or nil. For user, role,
channel, mentionable and attachment options this is the id;
get_user/2 and friends give you the struct.
Sends a message: the response, or a follow-up once answered. content is
a string, or message fields such as :content, :embeds, :components,
:files and :flags.
Like reply/2, but returns the context or raises Lingo.Error.
An attachment Discord sent along with the interaction.
A channel Discord sent along with the interaction.
A guild member Discord sent along with the interaction, by user id.
A message Discord sent along with the interaction; for message commands, ctx.target_id is the target.
A role Discord sent along with the interaction.
A user Discord sent along with the interaction.
Opens a modal built with Lingo.Component.Modal.modal/3. Must be the first response.
Like show_modal/2, but returns the context or raises Lingo.Error.
Edits the message a component is on, as the response to clicking it or after defer(ctx, update: true).
Like update/2, but returns the context or raises Lingo.Error.
Edits the response message. Ephemerality can't change after the first response.
Like update_reply/2, but returns the context or raises Lingo.Error.
Types
Message content: a string, or a keyword list or map of message fields.
@type t() :: %Lingo.Context{ app_permissions: String.t() | nil, application_id: String.t(), bot: atom() | nil, channel_id: String.t() | nil, command_name: String.t() | nil, component_type: atom() | integer() | nil, custom_id: String.t() | nil, deferred: boolean(), guild_id: String.t() | nil, guild_locale: String.t() | nil, interaction: Lingo.Type.Interaction.t() | nil, interaction_id: String.t(), interaction_token: String.t(), locale: String.t() | nil, member: Lingo.Type.Member.t() | nil, message: Lingo.Type.Message.t() | nil, options: %{optional(atom() | String.t()) => term()}, raw_options: [map()] | nil, replied: boolean(), resolved: map() | nil, target_id: String.t() | nil, type: Lingo.Type.Interaction.interaction_type(), user: Lingo.Type.User.t() | nil, user_id: String.t() | nil, values: [String.t()] }
Functions
Answers autocomplete with up to 25 choices, maps or keyword lists with :name and :value.
Like autocomplete_result/2, but returns the context or raises Lingo.Error.
Acknowledges the interaction now and answers later. Does nothing if
already deferred. Options: :ephemeral (only the user sees the answer) and
:update (for components: the answer edits their message).
Like defer/2, but returns the context or raises Lingo.Error.
Deletes the response message.
Like delete_reply/1, but returns the context or raises Lingo.Error.
Sends a response only the user who triggered the interaction can see.
Like ephemeral/2, but returns the context or raises Lingo.Error.
The option the user is typing in, during autocomplete, as {name, value}.
The attachment an option points at.
The channel an option points at.
The guild member an option points at.
Fetches the response message: the first reply/2 or its edits, not
follow-ups. Use its id with Lingo.Collector.await_component/2.
The role an option points at.
The user an option points at.
Launches the app's Activity, for entry point commands with the :app_handler handler.
Like launch_activity/1, but returns the context or raises Lingo.Error.
The value of a modal field, by its custom id. Same as option/2.
The value of a command option or modal field, or nil. For user, role,
channel, mentionable and attachment options this is the id;
get_user/2 and friends give you the struct.
Sends a message: the response, or a follow-up once answered. content is
a string, or message fields such as :content, :embeds, :components,
:files and :flags.
Like reply/2, but returns the context or raises Lingo.Error.
An attachment Discord sent along with the interaction.
A channel Discord sent along with the interaction.
A guild member Discord sent along with the interaction, by user id.
A message Discord sent along with the interaction; for message commands, ctx.target_id is the target.
A role Discord sent along with the interaction.
A user Discord sent along with the interaction.
Opens a modal built with Lingo.Component.Modal.modal/3. Must be the first response.
Like show_modal/2, but returns the context or raises Lingo.Error.
Edits the message a component is on, as the response to clicking it or after defer(ctx, update: true).
Like update/2, but returns the context or raises Lingo.Error.
Edits the response message. Ephemerality can't change after the first response.
Like update_reply/2, but returns the context or raises Lingo.Error.