EDA.Command.Option (EDA v0.3.0)

Copy Markdown View Source

Builder for command option objects.

Provides type-specific constructors that produce validated option structs. Options are added to commands via EDA.Command.option/2.

Example

import EDA.Command.Option

string("query", "Search query", required: true, min_length: 1, max_length: 100)
integer("count", "How many", min_value: 1, max_value: 25)
user("target", "The user to mention")
channel("channel", "Where to post", channel_types: [:guild_text])

string("color", "Pick a color",
  required: true,
  choices: [
    {"Red", "red"},
    {"Blue", "blue"},
    {"Green", "green"}
  ]
)

sub_command("add", "Add something", [
  string("name", "The name", required: true),
  integer("amount", "How many")
])

Summary

Functions

Creates an ATTACHMENT option (type 11).

Creates a BOOLEAN option (type 5).

Creates a CHANNEL option (type 7).

Creates an INTEGER option (type 4).

Adds localized name and/or description for a given locale.

Creates a MENTIONABLE option (type 9) — accepts users or roles.

Creates a NUMBER option (type 10) — double-precision float.

Creates a ROLE option (type 8).

Creates a STRING option (type 3).

Creates a SUB_COMMAND option (type 1) with nested options.

Creates a SUB_COMMAND_GROUP option (type 2) containing sub_commands.

Converts the option struct to a plain map for the Discord API.

Creates a USER option (type 6).

Types

t()

@type t() :: %EDA.Command.Option{
  autocomplete: boolean() | nil,
  channel_types: [non_neg_integer()] | nil,
  choices: [map()] | nil,
  description: String.t(),
  description_localizations: term(),
  max_length: pos_integer() | nil,
  max_value: number() | nil,
  min_length: non_neg_integer() | nil,
  min_value: number() | nil,
  name: String.t(),
  name_localizations: term(),
  options: [t()] | nil,
  required: boolean() | nil,
  type: 1..11
}

Functions

attachment(name, description, opts \\ [])

@spec attachment(String.t(), String.t(), keyword()) :: t()

Creates an ATTACHMENT option (type 11).

boolean(name, description, opts \\ [])

@spec boolean(String.t(), String.t(), keyword()) :: t()

Creates a BOOLEAN option (type 5).

channel(name, description, opts \\ [])

@spec channel(String.t(), String.t(), keyword()) :: t()

Creates a CHANNEL option (type 7).

Options

  • :channel_types - list of channel type atoms to restrict selection. Valid types: :guild_text, :dm, :guild_voice, :group_dm, :guild_category, :guild_announcement, :announcement_thread, :public_thread, :private_thread, :guild_stage_voice, :guild_forum, :guild_media

integer(name, description, opts \\ [])

@spec integer(String.t(), String.t(), keyword()) :: t()

Creates an INTEGER option (type 4).

localize(opt, locale, opts)

@spec localize(t(), String.t(), keyword()) :: t()

Adds localized name and/or description for a given locale.

Examples

string("query", "Search query")
|> localize("fr", name: "requête", description: "Requête de recherche")

mentionable(name, description, opts \\ [])

@spec mentionable(String.t(), String.t(), keyword()) :: t()

Creates a MENTIONABLE option (type 9) — accepts users or roles.

number(name, description, opts \\ [])

@spec number(String.t(), String.t(), keyword()) :: t()

Creates a NUMBER option (type 10) — double-precision float.

role(name, description, opts \\ [])

@spec role(String.t(), String.t(), keyword()) :: t()

Creates a ROLE option (type 8).

string(name, description, opts \\ [])

@spec string(String.t(), String.t(), keyword()) :: t()

Creates a STRING option (type 3).

sub_command(name, description, options \\ [])

@spec sub_command(String.t(), String.t(), [t()]) :: t()

Creates a SUB_COMMAND option (type 1) with nested options.

sub_command_group(name, description, sub_commands)

@spec sub_command_group(String.t(), String.t(), [t()]) :: t()

Creates a SUB_COMMAND_GROUP option (type 2) containing sub_commands.

to_map(opt)

@spec to_map(t()) :: map()

Converts the option struct to a plain map for the Discord API.

user(name, description, opts \\ [])

@spec user(String.t(), String.t(), keyword()) :: t()

Creates a USER option (type 6).