Builder for Discord Application Commands (slash commands, user commands, message commands).
Provides a pipe-friendly API with eager validation against Discord's limits.
Example
import EDA.Command
import EDA.Command.Option
# Simple slash command
ping = slash("ping", "Pings the bot")
# Command with options
greet =
slash("greet", "Greets someone")
|> option(string("message", "The greeting", required: true))
|> option(user("target", "Who to greet"))
|> option(integer("times", "How many times", min_value: 1, max_value: 10))
# Command with subcommands
role =
slash("role", "Manage roles")
|> option(
sub_command("add", "Add a role", [
role("role", "The role to add", required: true),
user("target", "The user")
])
)
|> option(
sub_command("remove", "Remove a role", [
role("role", "The role to remove", required: true)
])
)
# Context menu commands
info = user_command("User Info")
quote_msg = message_command("Quote Message")
# Register
EDA.API.Command.create_guild(guild_id, greet)
EDA.API.Command.bulk_overwrite_guild(guild_id, [ping, greet, role])
Summary
Functions
Sets the interaction contexts where the command can be used.
Sets the default member permissions required to use this command.
Adds localized name and/or description for a given locale.
Creates a message context menu command (type 3).
Marks the command as age-restricted (NSFW).
Adds an option to the command (max 25 options).
Creates a new slash command (CHAT_INPUT, type 1).
Converts the command struct to a plain map for the Discord API.
Creates a user context menu command (type 2).
Types
@type command_type() :: :slash | :user | :message
@type context() :: :guild | :bot_dm | :private_channel
@type t() :: %EDA.Command{ contexts: [non_neg_integer()] | nil, default_member_permissions: String.t() | nil, description: String.t() | nil, description_localizations: map() | nil, name: String.t(), name_localizations: map() | nil, nsfw: boolean(), options: [EDA.Command.Option.t()], type: 1 | 2 | 3 }
Functions
Sets the interaction contexts where the command can be used.
Accepts a list of :guild, :bot_dm, :private_channel.
Example
slash("ping", "Pong") |> contexts([:guild, :bot_dm])
Sets the default member permissions required to use this command.
Accepts a permission bitfield as a string (e.g. "8" for Administrator).
Use "0" to disable for everyone except admins.
Adds localized name and/or description for a given locale.
Discord locale codes: "fr", "de", "es-ES", "ja", "pt-BR", etc.
See Discord docs for the full list.
Examples
slash("ping", "Pings the bot")
|> localize("fr", name: "ping", description: "Ping le bot")
|> localize("de", description: "Pingt den Bot")
Creates a message context menu command (type 3).
Name must be 1-32 characters. Mixed case and spaces allowed.
Marks the command as age-restricted (NSFW).
@spec option(t(), EDA.Command.Option.t()) :: t()
Adds an option to the command (max 25 options).
Only valid for slash commands (type 1).
Creates a new slash command (CHAT_INPUT, type 1).
Name must be 1-32 lowercase characters (a-z, 0-9, -, _). Description must be 1-100 characters.
Converts the command struct to a plain map for the Discord API.
Creates a user context menu command (type 2).
Name must be 1-32 characters. Mixed case and spaces allowed.