glyde/application_command

Application commands: what a bot registers, as opposed to what a user invoked. glyde/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

  • 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),
    )

    Arguments

    type_

    Optional on the wire, defaulting to CHAT_INPUT. A value this build has no name for fails the decode.

    guild_id

    Absent for a global command.

    name_localizations

    Only with ?with_localizations=true.

    description

    The EMPTY STRING for USER and MESSAGE commands, and never null.

    options

    CHAT_INPUT only.

    default_member_permissions

    None is no override. Some of the empty set, the string “0”, is admins only. Collapsing the two exposes or hides a command.

    dm_permission

    Deprecated for contexts, and still sent.

    contexts

    None is absent or null, which Discord reads as every context.

    version

    A snowflake despite the name, bumped on every substantial change.

    name_localized

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

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(v) {
  ApplicationCommandOptionChoice(
    name: String,
    name_localizations: option.Option(dict.Dict(String, String)),
    value: v,
  )
}

Constructors

  • ApplicationCommandOptionChoice(
      name: String,
      name_localizations: option.Option(dict.Dict(String, String)),
      value: v,
    )

A value this build has no name for is dropped from options on decode.

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

Constructors

  • SubCommand
  • SubCommandGroup
  • StringOption
  • IntegerOption
  • BooleanOption
  • UserOption
  • ChannelOption
  • RoleOption
  • MentionableOption
  • NumberOption
  • AttachmentOption

A value this build has no name for fails the decode.

pub type ApplicationCommandType {
  ChatInput
  UserCommand
  MessageCommand
  PrimaryEntryPoint
}

Constructors

  • ChatInput
  • UserCommand
  • MessageCommand
  • PrimaryEntryPoint

    Activities only.

How an app was installed. A value this build has no name for is dropped from integration_types on decode.

pub type ApplicationIntegrationType {
  GuildInstall
  UserInstall
}

Constructors

  • GuildInstall
  • UserInstall

A choice’s value when the option’s type is not known at compile time: an autocomplete response answers whichever option the user is typing. The three registered kinds hold the bare String, Int or Float instead.

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

Constructors

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

What both scopes take. The three command types share every field here, and kind holds what only a slash command has.

This is the guild body as it stands. Wrap it in global for the two fields a global command may also carry.

pub type CreateApplicationCommand {
  CreateApplicationCommand(
    kind: CreateKind,
    name: String,
    name_localizations: dict.Dict(String, String),
    default_member_permissions: option.Option(
      permissions.Permissions,
    ),
    nsfw: Bool,
  )
}

Constructors

  • CreateApplicationCommand(
      kind: CreateKind,
      name: String,
      name_localizations: dict.Dict(String, String),
      default_member_permissions: option.Option(
        permissions.Permissions,
      ),
      nsfw: Bool,
    )

    Arguments

    name

    1 to 32 characters, lowercase for a slash command.

    name_localizations

    Empty writes no key.

    default_member_permissions

    None leaves Discord’s default, which is that everyone can use it. Some(permissions.none()) is admins only.

Which of the three a body registers. A context-menu command with a description or an option is a 400, so neither is reachable from one.

pub type CreateKind {
  AsChatInput(
    description: String,
    description_localizations: dict.Dict(String, String),
    options: List(ApplicationCommandOption),
  )
  AsUserCommand
  AsMessageCommand
}

Constructors

  • AsChatInput(
      description: String,
      description_localizations: dict.Dict(String, String),
      options: List(ApplicationCommandOption),
    )

    A slash command.

    Arguments

    description

    1 to 100 characters.

  • AsUserCommand

    Right-click on a user.

  • AsMessageCommand

    Right-click on a message.

PATCH /applications/{app}/guilds/{guild}/commands/{cmd}, and the half a global edit shares with it. Any field sent overwrites.

Field only where null is legal. Discord answers 400 to a null name, description, options or nsfw, so those four stay Option. Some([]) empties the option list.

pub type EditApplicationCommand {
  EditApplicationCommand(
    name: option.Option(String),
    description: option.Option(String),
    options: option.Option(List(ApplicationCommandOption)),
    nsfw: option.Option(Bool),
    name_localizations: field.Field(dict.Dict(String, String)),
    description_localizations: field.Field(
      dict.Dict(String, String),
    ),
    default_member_permissions: field.Field(
      permissions.Permissions,
    ),
  )
}

Constructors

PATCH /applications/{app}/commands/{cmd}: the shared fields plus the two the guild route answers 400 to. A null integration_types is a 400 too, so that one is an Option.

pub type EditGlobalCommand {
  EditGlobalCommand(
    command: EditApplicationCommand,
    integration_types: option.Option(
      List(ApplicationIntegrationType),
    ),
    contexts: field.Field(List(InteractionContextType)),
  )
}

Constructors

A command registered globally. integration_types and contexts are a 400 on the guild route, so they exist here and nowhere else.

pub type GlobalCommand {
  GlobalCommand(
    command: CreateApplicationCommand,
    integration_types: List(ApplicationIntegrationType),
    contexts: List(InteractionContextType),
  )
}

Constructors

Where in Discord a command may be used, or was used from. A value this build has no name for is dropped from contexts on decode.

pub type InteractionContextType {
  GuildContext
  BotDmContext
  PrivateChannelContext
}

Constructors

  • GuildContext
  • BotDmContext
  • PrivateChannelContext

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(String),
    min_length: option.Option(Int),
    max_length: option.Option(Int),
  )
  IntegerKind(
    suggestions: Suggestions(Int),
    min: option.Option(Int),
    max: option.Option(Int),
  )
  NumberKind(
    suggestions: Suggestions(Float),
    min: option.Option(Float),
    max: option.Option(Float),
  )
  ChannelKind(channel_types: List(channel.ChannelType))
  BooleanKind
  UserKind
  RoleKind
  MentionableKind
  AttachmentKind
}

Constructors

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. v is the option’s own value type, so a STRING option with an integer choice does not typecheck either.

pub type Suggestions(v) {
  Choices(List(ApplicationCommandOptionChoice(v)))
  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 bulk_global_body(
  commands: List(GlobalCommand),
) -> body.Body

The body for PUT /applications/{app}/commands, whose payload is a top-level array. An empty list deletes every global command.

pub fn bulk_guild_body(
  commands: List(CreateApplicationCommand),
) -> body.Body

The same for PUT /applications/{app}/guilds/{guild}/commands, which empties that guild rather than the application.

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 chat_input(
  name name: String,
  description description: String,
  options options: List(ApplicationCommandOption),
) -> CreateApplicationCommand

The same slash command with its parameters. The encoder puts the required ones first, so they can be listed in any order.

pub fn choice_to_json(
  choice: ApplicationCommandOptionChoice(v),
  encode: fn(v) -> json.Json,
) -> json.Json
pub fn choice_value_to_json(value: ChoiceValue) -> json.Json
pub fn command_type_from_int(
  value: Int,
) -> option.Option(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,
) -> option.Option(InteractionContextType)
pub fn context_type_to_int(value: InteractionContextType) -> Int
pub fn context_type_to_json(
  value: InteractionContextType,
) -> json.Json
pub fn create_global_command(
  api: api.Api,
  application: id.Id(id.Application),
  create: GlobalCommand,
) -> Result(ApplicationCommand, api.CallFailure)

POST /applications/{application.id}/commands. Safe to run on every boot: Discord answers 200 and updates in place when the name already exists.

pub fn create_global_command_call(
  application: id.Id(id.Application),
  create: GlobalCommand,
) -> rest.Call(ApplicationCommand)

The bare Call, for driving glyde/rest yourself.

pub fn create_guild_command(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  create: CreateApplicationCommand,
) -> Result(ApplicationCommand, api.CallFailure)

POST /applications/{application.id}/guilds/{guild.id}/commands. Appears immediately, where a global command can take an hour to propagate.

pub fn create_guild_command_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  create: CreateApplicationCommand,
) -> rest.Call(ApplicationCommand)

The Call for [create_guild_command], for building the request without sending it.

pub fn delete_global_command(
  api: api.Api,
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
) -> Result(Nil, api.CallFailure)
pub fn delete_global_command_call(
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
) -> rest.Call(Nil)

The Call for [delete_global_command], for building the request without sending it.

pub fn delete_guild_command(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
) -> Result(Nil, api.CallFailure)
pub fn delete_guild_command_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
) -> rest.Call(Nil)

The Call for [delete_guild_command], for building the request without sending it.

pub fn edit_global() -> EditGlobalCommand

An edit of a global command, touching nothing. Reach the shared fields through command.

pub fn edit_global_body(command: EditGlobalCommand) -> body.Body
pub fn edit_global_command(
  api: api.Api,
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
  edit: EditGlobalCommand,
) -> Result(ApplicationCommand, api.CallFailure)

PATCH /applications/{application.id}/commands/{id}.

pub fn edit_global_command_call(
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
  edit: EditGlobalCommand,
) -> rest.Call(ApplicationCommand)

The Call for [edit_global_command], for building the request without sending it.

pub fn edit_guild_body(
  command: EditApplicationCommand,
) -> body.Body
pub fn edit_guild_command(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
  edit: EditApplicationCommand,
) -> Result(ApplicationCommand, api.CallFailure)

PATCH /applications/{application.id}/guilds/{guild.id}/commands/{id}.

pub fn edit_guild_command_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
  edit: EditApplicationCommand,
) -> rest.Call(ApplicationCommand)

The Call for [edit_guild_command], for building the request without sending it.

pub fn get_global_command(
  api: api.Api,
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
) -> Result(ApplicationCommand, api.CallFailure)
pub fn get_global_command_call(
  application: id.Id(id.Application),
  command_id: id.Id(id.Command),
) -> rest.Call(ApplicationCommand)

The Call for [get_global_command], for building the request without sending it.

pub fn get_global_commands(
  api: api.Api,
  application: id.Id(id.Application),
  with_localizations with_localizations: Bool,
) -> Result(List(ApplicationCommand), api.CallFailure)

GET /applications/{application.id}/commands. name and description arrive either way. with_localizations swaps the single name_localized and description_localized for the full name_localizations and description_localizations maps.

pub fn get_global_commands_call(
  application: id.Id(id.Application),
  with_localizations with_localizations: Bool,
) -> rest.Call(List(ApplicationCommand))

The Call for [get_global_commands], for building the request without sending it.

pub fn get_guild_command(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
) -> Result(ApplicationCommand, api.CallFailure)
pub fn get_guild_command_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  command_id: id.Id(id.Command),
) -> rest.Call(ApplicationCommand)

The Call for [get_guild_command], for building the request without sending it.

pub fn get_guild_commands(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  with_localizations with_localizations: Bool,
) -> Result(List(ApplicationCommand), api.CallFailure)
pub fn get_guild_commands_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  with_localizations with_localizations: Bool,
) -> rest.Call(List(ApplicationCommand))

The Call for [get_guild_commands], for building the request without sending it.

pub fn global(command: CreateApplicationCommand) -> GlobalCommand

The same command, global, with Discord’s defaults for the two fields only this scope has. Set either with a record update.

pub fn global_body(command: GlobalCommand) -> body.Body

The body for POST /applications/{app}/commands.

pub fn global_to_json(command: GlobalCommand) -> json.Json
pub fn guild_body(command: CreateApplicationCommand) -> body.Body

The body for POST /applications/{app}/guilds/{guild}/commands.

pub fn guild_to_json(
  command: CreateApplicationCommand,
) -> 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,
) -> option.Option(ApplicationIntegrationType)
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 new_chat_input(
  name name: String,
  description description: String,
) -> CreateApplicationCommand
pub fn new_message_command(
  name name: String,
) -> CreateApplicationCommand
pub fn new_user_command(
  name name: String,
) -> CreateApplicationCommand
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_decoder() -> decode.Decoder(
  option.Option(ApplicationCommandOption),
)

An option whose type this build has no name for yields None, so options holds only what it can name.

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,
) -> option.Option(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 set_global_commands(
  api: api.Api,
  application: id.Id(id.Application),
  commands: List(GlobalCommand),
) -> Result(List(ApplicationCommand), api.CallFailure)

PUT /applications/{application.id}/commands, replacing the whole set. Every command type at once: a list holding only slash commands silently deletes the application’s user and message commands.

pub fn set_global_commands_call(
  application: id.Id(id.Application),
  commands: List(GlobalCommand),
) -> rest.Call(List(ApplicationCommand))

The Call for [set_global_commands], for building the request without sending it.

pub fn set_guild_commands(
  api: api.Api,
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  commands: List(CreateApplicationCommand),
) -> Result(List(ApplicationCommand), api.CallFailure)

PUT /applications/{application.id}/guilds/{guild.id}/commands, which replaces every command type this application has in that guild.

pub fn set_guild_commands_call(
  application: id.Id(id.Application),
  guild: id.Id(id.Guild),
  commands: List(CreateApplicationCommand),
) -> rest.Call(List(ApplicationCommand))

The Call for [set_guild_commands], for building the request without sending it.

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