Nostrum.Api.ApplicationCommand (nostrum v0.11.0-dev)

View Source

Module for interacting with Discord's application commands.

See: https://discord.com/developers/docs/interactions/application-commands

Summary

Functions

Edits command permissions for a specific command for your application in a guild. You can only add up to 10 permission overwrites for a command.

Overwrite the existing global application commands.

Overwrite the existing guild application commands on the specified guild.

Create a new global application command.

Create a guild application command on the specified guild.

Delete an existing global application command.

Edits command permissions for a specific command for your application in a guild. You can only add up to 10 permission overwrites for a command.

Update an existing global application command.

Fetch all guild application commands for the given guild.

Fetches command permissions for all commands for your application in a guild.

Fetches command permissions for a specific command for your application in a guild.

Functions

batch_edit_permissions(application_id \\ Me.get().id, guild_id, permissions)

(since 1.x.x)

Edits command permissions for a specific command for your application in a guild. You can only add up to 10 permission overwrites for a command.

Parameters

  • application_id: Application ID commands are registered under. If not given, this will be fetched from Me.
  • guild_id: Guild ID to fetch command permissions from.
  • command_id: Command ID to fetch permissions for.
  • permissions: List of partial guild application command permissions with id and permissions. You can add up to 10 overwrites per command.

Return value

This method returns a guild application command permission object, see all available values on the Discord API docs.

bulk_overwrite_global_commands(application_id \\ Me.get().id, commands)

(since 1.x.x)
@spec bulk_overwrite_global_commands(Nostrum.Struct.User.id(), [
  Nostrum.Struct.ApplicationCommand.application_command_map()
]) :: {:ok, [map()]} | Nostrum.Api.error()

Overwrite the existing global application commands.

This action will:

  • Create any command that was provided and did not already exist
  • Update any command that was provided and already existed if its configuration changed
  • Delete any command that was not provided but existed on Discord's end

Updates will be available in all guilds after 1 hour. Commands that do not already exist will count toward daily application command create limits.

Parameters

  • application_id: Application ID for which to overwrite the commands. If not given, this will be fetched from Me.
  • commands: List of command configurations, see the linked API documentation for reference.

Return value

Updated list of global application commands. See the official reference: https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands

bulk_overwrite_guild_commands(application_id \\ Me.get().id, guild_id, commands)

(since 1.x.x)

Overwrite the existing guild application commands on the specified guild.

This action will:

  • Create any command that was provided and did not already exist
  • Update any command that was provided and already existed if its configuration changed
  • Delete any command that was not provided but existed on Discord's end

Parameters

  • application_id: Application ID for which to overwrite the commands. If not given, this will be fetched from Me.
  • guild_id: Guild on which to overwrite the commands.
  • commands: List of command configurations, see the linked API documentation for reference.

Return value

Updated list of guild application commands. See the official reference: https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands

create_global_command(application_id \\ Me.get().id, command)

(since 0.10.1)

Create a new global application command.

The new command will be available on all guilds in around an hour. If you want to test commands, use create_guild_command/2 instead, as commands will become available instantly there. If an existing command with the same name exists, it will be overwritten.

Parameters

  • application_id: Application ID for which to create the command. If not given, this will be fetched from Me.
  • command: Command configuration, see the linked API documentation for reference.

Return value

The created command. See the official reference: https://discord.com/developers/docs/interactions/application-commands#create-global-application-command

Example

Nostrum.Api.ApplicationCommand.create_global_command(
  %{name: "edit", description: "ed, man! man, ed", options: []}
)

create_guild_command(application_id \\ Me.get().id, guild_id, command)

(since 0.10.1)

Create a guild application command on the specified guild.

The new command will be available immediately.

Parameters

  • application_id: Application ID for which to create the command. If not given, this will be fetched from Me.
  • guild_id: Guild on which to create the command.
  • command: Command configuration, see the linked API documentation for reference.

Return value

The created command. See the official reference: https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command

delete_global_command(application_id \\ Me.get().id, command_id)

(since 0.10.1)
@spec delete_global_command(Nostrum.Struct.User.id(), Nostrum.Snowflake.t()) ::
  {:ok} | Nostrum.Api.error()

Delete an existing global application command.

Parameters

  • application_id: Application ID for which to create the command. If not given, this will be fetched from Me.
  • command_id: The current snowflake of the command.

delete_guild_command(application_id \\ Me.get().id, guild_id, command_id)

(since 0.10.1)
@spec delete_guild_command(
  Nostrum.Struct.User.id(),
  Nostrum.Struct.Guild.id(),
  Nostrum.Snowflake.t()
) ::
  {:ok} | Nostrum.Api.error()

Delete an existing guild application command.

Parameters

  • application_id: Application ID for which to create the command. If not given, this will be fetched from Me.
  • guild_id: The guild on which the command exists.
  • command_id: The current snowflake of the command.

edit_command_permissions(application_id \\ Me.get().id, guild_id, command_id, permissions)

(since 1.x.x)

Edits command permissions for a specific command for your application in a guild. You can only add up to 10 permission overwrites for a command.

Parameters

  • application_id: Application ID commands are registered under. If not given, this will be fetched from Me.
  • guild_id: Guild ID to fetch command permissions from.
  • command_id: Command ID to fetch permissions for.
  • permissions: List of application command permissions

Return value

This method returns a guild application command permission object, see all available values on the Discord API docs.

edit_global_command(application_id \\ Me.get().id, command_id, command)

(since 0.10.1)

Update an existing global application command.

The updated command will be available on all guilds in around an hour.

Parameters

  • application_id: Application ID for which to edit the command. If not given, this will be fetched from Me.
  • command_id: The current snowflake of the command.
  • command: Command configuration, see the linked API documentation for reference.

Return value

The updated command. See the official reference: https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command

edit_guild_command(application_id \\ Me.get().id, guild_id, command_id, command)

(since 0.10.1)

Update an existing guild application command.

The updated command will be available immediately.

Parameters

  • application_id: Application ID for which to edit the command. If not given, this will be fetched from Me.
  • guild_id: Guild for which to update the command.
  • command_id: The current snowflake of the command.
  • command: Command configuration, see the linked API documentation for reference.

Return value

The updated command. See the official reference: https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command

global_commands(application_id \\ Me.get().id)

(since 0.10.1)
@spec global_commands(Nostrum.Struct.User.id()) ::
  {:ok, [map()]} | Nostrum.Api.error()

Fetch all global commands.

Parameters

  • application_id: Application ID for which to search commands. If not given, this will be fetched from Me.

Return value

A list of ApplicationCommands on success. See the official reference: https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure

Example

iex> Nostrum.Api.global_commands
{:ok,
 [
   %{
     application_id: "455589479713865749",
     description: "ed, man! man, ed",
     id: "789841753196331029",
     name: "edit"
   }
 ]}

guild_commands(application_id \\ Me.get().id, guild_id)

(since 0.10.1)
@spec guild_commands(Nostrum.Struct.User.id(), Nostrum.Struct.Guild.id()) ::
  {:ok, [map()]} | Nostrum.Api.error()

Fetch all guild application commands for the given guild.

Parameters

  • application_id: Application ID for which to fetch commands. If not given, this will be fetched from Me.
  • guild_id: The guild ID for which guild application commands should be requested.

Return value

A list of ApplicationCommands on success. See the official reference: https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure

guild_permissions(application_id \\ Me.get().id, guild_id)

(since 1.x.x)
@spec guild_permissions(Nostrum.Struct.User.id(), Nostrum.Struct.Guild.id()) ::
  {:ok, [map()]} | Nostrum.Api.error()

Fetches command permissions for all commands for your application in a guild.

Parameters

  • application_id: Application ID commands are registered under. If not given, this will be fetched from Me.
  • guild_id: Guild ID to fetch command permissions from.

Return value

This method returns a list of guild application command permission objects, see all available values on the Discord API docs.

permissions(application_id \\ Me.get().id, guild_id, command_id)

(since 1.x.x)

Fetches command permissions for a specific command for your application in a guild.

Parameters

  • application_id: Application ID commands are registered under. If not given, this will be fetched from Me.
  • guild_id: Guild ID to fetch command permissions from.
  • command_id: Command ID to fetch permissions for.

Return value

This method returns a single guild application command permission object, see all available values on the Discord API docs.