glyde/model/application_command

Application commands: what a bot registers, as opposed to what a user invoked. model/interaction is the other half.

InteractionContextType and ApplicationIntegrationType are declared at registration, so they live here rather than in interaction.

Types

pub type ApplicationCommand {
  ApplicationCommand(
    id: id.Id(id.Command),
    type_: ApplicationCommandType,
    application_id: id.Id(id.Application),
    guild_id: option.Option(id.Id(id.Guild)),
    name: String,
    name_localizations: option.Option(dict.Dict(String, String)),
    description: String,
    description_localizations: option.Option(
      dict.Dict(String, String),
    ),
    options: List(ApplicationCommandOption),
    default_member_permissions: option.Option(
      permissions.Permissions,
    ),
    dm_permission: option.Option(Bool),
    nsfw: Bool,
    integration_types: List(ApplicationIntegrationType),
    contexts: option.Option(List(InteractionContextType)),
    version: String,
    name_localized: option.Option(String),
    description_localized: option.Option(String),
  )
}

Constructors

One parameter of a command. Everything an option type does not have goes in kind, so a length bound on an INTEGER does not typecheck.

pub type ApplicationCommandOption {
  ApplicationCommandOption(
    name: String,
    name_localizations: option.Option(dict.Dict(String, String)),
    description: String,
    description_localizations: option.Option(
      dict.Dict(String, String),
    ),
    required: Bool,
    kind: OptionKind,
    name_localized: option.Option(String),
    description_localized: option.Option(String),
  )
}

Constructors

  • ApplicationCommandOption(
      name: String,
      name_localizations: option.Option(dict.Dict(String, String)),
      description: String,
      description_localizations: option.Option(
        dict.Dict(String, String),
      ),
      required: Bool,
      kind: OptionKind,
      name_localized: option.Option(String),
      description_localized: option.Option(String),
    )

    Arguments

    name

    1 to 32 characters.

    description

    1 to 100 characters.

    required

    Discord answers 50035 unless every required option comes before every optional one. options_to_json sorts them, so the order they are built in does not matter.

    name_localized

    Only when the request did not ask for the full dictionaries.

pub type ApplicationCommandOptionChoice {
  ApplicationCommandOptionChoice(
    name: String,
    name_localizations: option.Option(dict.Dict(String, String)),
    value: ChoiceValue,
  )
}

Constructors

pub type ApplicationCommandOptionType {
  SubCommand
  SubCommandGroup
  StringOption
  IntegerOption
  BooleanOption
  UserOption
  ChannelOption
  RoleOption
  MentionableOption
  NumberOption
  AttachmentOption
  UnknownOptionType(Int)
}

Constructors

  • SubCommand
  • SubCommandGroup
  • StringOption
  • IntegerOption
  • BooleanOption
  • UserOption
  • ChannelOption
  • RoleOption
  • MentionableOption
  • NumberOption
  • AttachmentOption
  • UnknownOptionType(Int)
pub type ApplicationCommandType {
  ChatInput
  UserCommand
  MessageCommand
  PrimaryEntryPoint
  UnknownCommandType(Int)
}

Constructors

  • ChatInput
  • UserCommand
  • MessageCommand
  • PrimaryEntryPoint

    Activities only.

  • UnknownCommandType(Int)

How an app was installed. Also a JSON object key, as “0” or “1”.

pub type ApplicationIntegrationType {
  GuildInstall
  UserInstall
  UnknownIntegrationType(Int)
  UnknownIntegrationKey(String)
}

Constructors

  • GuildInstall
  • UserInstall
  • UnknownIntegrationType(Int)
  • UnknownIntegrationKey(String)

    An object key that was not a number at all. It keeps the raw key, because this is a Dict key: one shared sentinel would drop every unparseable entry but the last.

A choice’s value, in the type its option declares.

pub type ChoiceValue {
  StringChoice(String)
  IntChoice(Int)
  FloatChoice(Float)
}

Constructors

  • StringChoice(String)
  • IntChoice(Int)
  • FloatChoice(Float)

Where in Discord a command may be used, or was used from.

pub type InteractionContextType {
  GuildContext
  BotDmContext
  PrivateChannelContext
  UnknownContext(Int)
}

Constructors

  • GuildContext
  • BotDmContext
  • PrivateChannelContext
  • UnknownContext(Int)

The option type and the fields that type is allowed to carry, in one tag.

pub type OptionKind {
  SubCommandKind(options: List(ApplicationCommandOption))
  SubCommandGroupKind(options: List(ApplicationCommandOption))
  StringKind(
    suggestions: Suggestions,
    min_length: option.Option(Int),
    max_length: option.Option(Int),
  )
  IntegerKind(
    suggestions: Suggestions,
    min: option.Option(Int),
    max: option.Option(Int),
  )
  NumberKind(
    suggestions: Suggestions,
    min: option.Option(Float),
    max: option.Option(Float),
  )
  ChannelKind(channel_types: List(channel.ChannelType))
  BooleanKind
  UserKind
  RoleKind
  MentionableKind
  AttachmentKind
  UnknownKind(
    type_: Int,
    choices: List(ApplicationCommandOptionChoice),
    options: List(ApplicationCommandOption),
    channel_types: List(channel.ChannelType),
    min_value: option.Option(OptionNumberLimit),
    max_value: option.Option(OptionNumberLimit),
    min_length: option.Option(Int),
    max_length: option.Option(Int),
    autocomplete: Bool,
    raw: component.RawPayload,
  )
}

Constructors

A bound as it arrives on the wire, before the declared type narrows it to the Int or Float its kind holds. Whole for INTEGER, fractional for NUMBER.

pub type OptionNumberLimit {
  IntLimit(Int)
  FloatLimit(Float)
}

Constructors

  • IntLimit(Int)
  • FloatLimit(Float)

Where a STRING, INTEGER or NUMBER option gets its values from. Discord answers 50035 to choices beside autocomplete, so the two are one tag and the pair cannot be built.

pub type Suggestions {
  Choices(List(ApplicationCommandOptionChoice))
  Autocomplete
  NoSuggestions
}

Constructors

Values

pub fn attachment_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption
pub fn boolean_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption
pub fn channel_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption

Offers every channel type. Narrow it with a record update on the kind.

pub fn choice_value_decoder(
  option_type: ApplicationCommandOptionType,
) -> decode.Decoder(ChoiceValue)

A choice’s value, likewise picked by the option’s declared type, and likewise tolerant for a type this build does not know.

pub fn choice_value_to_json(value: ChoiceValue) -> json.Json
pub fn command_type_from_int(
  value: Int,
) -> ApplicationCommandType
pub fn command_type_to_int(value: ApplicationCommandType) -> Int
pub fn command_type_to_json(
  value: ApplicationCommandType,
) -> json.Json
pub fn context_type_from_int(
  value: Int,
) -> InteractionContextType
pub fn context_type_to_int(value: InteractionContextType) -> Int
pub fn context_type_to_json(
  value: InteractionContextType,
) -> json.Json
pub fn integer_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption

An INTEGER with no suggestions and no bounds.

pub fn integration_type_from_int(
  value: Int,
) -> ApplicationIntegrationType
pub fn integration_type_key_decoder() -> decode.Decoder(
  ApplicationIntegrationType,
)

From a JSON object KEY, the string “0” or “1”. A key that is not a number keeps its text rather than failing the interaction.

pub fn integration_type_to_int(
  value: ApplicationIntegrationType,
) -> Int
pub fn integration_type_to_json(
  value: ApplicationIntegrationType,
) -> json.Json
pub fn localizations_to_json(
  entries: dict.Dict(String, String),
) -> json.Json

Sorted by locale: Dict iteration order is unspecified and these become request bytes.

pub fn mentionable_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption

A user or a role, resolved either way.

pub fn number_limit_decoder(
  option_type: ApplicationCommandOptionType,
) -> decode.Decoder(OptionNumberLimit)

The declared type picks the variant, not the JSON: Discord writes a whole NUMBER bound as 5, and sending an INTEGER bound as 5.0 is a 400. A type this build does not know takes either shape, so one new option type does not sink the whole response.

pub fn number_limit_to_json(
  value: OptionNumberLimit,
) -> json.Json
pub fn number_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption

A NUMBER with no suggestions and no bounds.

pub fn option(
  name name: String,
  description description: String,
  kind kind: OptionKind,
) -> ApplicationCommandOption

Any option, with everything its type is allowed to carry in kind: option(name: "who", description: "d", kind: UserKind), or SubCommandKind(options:) for a subcommand, the deepest of the three levels Discord allows being a group holding subcommands holding values.

Optional, no localizations: Discord’s own defaults, not ours. Change any of them with a record update.

pub fn option_kind_type(
  kind: OptionKind,
) -> ApplicationCommandOptionType

The type a kind sends, the way component.row_child_type works.

pub fn option_to_json(
  option: ApplicationCommandOption,
) -> json.Json
pub fn option_type_from_int(
  value: Int,
) -> ApplicationCommandOptionType
pub fn option_type_to_int(
  value: ApplicationCommandOptionType,
) -> Int
pub fn option_type_to_json(
  value: ApplicationCommandOptionType,
) -> json.Json
pub fn options_to_json(
  options: List(ApplicationCommandOption),
) -> json.Json

An option list as Discord wants it: every required option first, or it answers 50035. list.partition keeps the order inside each group, so a caller’s own ordering survives.

pub fn role_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption
pub fn string_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption

A STRING with no suggestions and no length bounds.

pub fn sub_command(
  name name: String,
  description description: String,
  options options: List(ApplicationCommandOption),
) -> ApplicationCommandOption
pub fn sub_command_group(
  name name: String,
  description description: String,
  options options: List(ApplicationCommandOption),
) -> ApplicationCommandOption
pub fn user_option(
  name name: String,
  description description: String,
) -> ApplicationCommandOption
Search Document