glyde/payload/command

Bodies for registering and editing application commands.

integration_types and contexts are a 400 on /applications/{app}/guilds/{g}/commands, so they live on the global shapes only: a guild body has no field to put them in, and the same value cannot reach both scopes. The trap left is the bulk overwrite PUT, which replaces every command type at once, so a startup sync deletes the bot’s context-menu commands unless they are in the list.

Types

Where a global command can be used. Send-only, so no unknown tail: see InstallContext.

pub type CommandContext {
  GuildContext
  BotDmContext
  PrivateChannelContext
}

Constructors

  • GuildContext
  • BotDmContext

    A DM with the bot itself.

  • PrivateChannelContext

    A group DM, or a DM with anyone but the bot.

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 {
  ChatInput(
    description: String,
    description_localizations: dict.Dict(String, String),
    options: List(application_command.ApplicationCommandOption),
  )
  UserCommand
  MessageCommand
}

Constructors

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

    A slash command.

    Arguments

    description

    1 to 100 characters.

  • UserCommand

    Right-click on a user.

  • MessageCommand

    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(application_command.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(InstallContext)),
    contexts: field.Field(List(CommandContext)),
  )
}

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(InstallContext),
    contexts: List(CommandContext),
  )
}

Constructors

Where a global command can be installed. model/application_command keeps an unknown tail on the decoded enum so one new install target cannot drop an interaction; going out, a target Discord does not know is a 400, so this side holds the two it accepts and nothing else.

pub type InstallContext {
  GuildInstall
  UserInstall
}

Constructors

  • GuildInstall

    Installed to a guild.

  • UserInstall

    Installed to a user, who then carries it everywhere.

Values

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 chat_input(
  name name: String,
  description description: String,
  options options: List(
    application_command.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 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_guild_body(
  command: EditApplicationCommand,
) -> body.Body
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 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
Search Document