Skip to content

ApplicationCommandManager

classe · Source

Manages API methods for application commands and stores their cache.

Extends: CachedManager

Properties

permissions

permissions: ApplicationCommandPermissionsManager

The manager for permissions of arbitrary commands on arbitrary guilds Source

cache

cache: Collection<Snowflake, ApplicationCommand>

The cache of this manager Source

_cache

readonly · private

_cache: Collection

The private cache of items for this manager. Source

holds

readonly · private

holds: function

The data structure belonging to this manager. Source

client

readonly

client: Client

The client that instantiated this Manager Source

Methods

commandPath

private

commandPath(options.id?: Snowflake, options.guildId?: Snowflake): Object

The APIRouter path to the commands Parameters

NameTypeDescription
options.id?SnowflakeThe application command's id
options.guildId?SnowflakeThe guild's id to use in the path,
ignored when using a GuildApplicationCommandManager

Returns: ObjectSource

fetch

async

async fetch(id?: Snowflake, options?: FetchApplicationCommandOptions): Promise<(ApplicationCommand|Collection<Snowflake, ApplicationCommand>)>

Obtains one or multiple application commands from Discord, or the cache if it's already available. Parameters

NameTypeDescription
id?SnowflakeThe application command's id
options?FetchApplicationCommandOptionsAdditional options for this fetch

Returns: Promise<(ApplicationCommand\|Collection<Snowflake, ApplicationCommand>)>

js
// Fetch a single command
client.application.commands.fetch('123456789012345678')
  .then(command => console.log(`Fetched command ${command.name}`))
  .catch(console.error);
js
// Fetch all commands
guild.commands.fetch()
  .then(commands => console.log(`Fetched ${commands.size} commands`))
  .catch(console.error);

Source

create

async

async create(command: ApplicationCommandDataResolvable, guildId?: Snowflake): Promise<ApplicationCommand>

Creates an application command. Parameters

NameTypeDescription
commandApplicationCommandDataResolvableThe command
guildId?SnowflakeThe guild's id to create this command in,
ignored when using a GuildApplicationCommandManager

Returns: Promise<ApplicationCommand>

js
// Create a new command
client.application.commands.create({
  name: 'test',
  description: 'A test command',
})
  .then(console.log)
  .catch(console.error);

Source

set

async

async set(commands: Array<ApplicationCommandDataResolvable>, guildId?: Snowflake): Promise<Collection<Snowflake, ApplicationCommand>>

Sets all the commands for this application or guild. Parameters

NameTypeDescription
commandsArray<ApplicationCommandDataResolvable>The commands
guildId?SnowflakeThe guild's id to create the commands in,
ignored when using a GuildApplicationCommandManager

Returns: Promise<Collection<Snowflake, ApplicationCommand>>

js
// Set all commands to just this one
client.application.commands.set([
  {
    name: 'test',
    description: 'A test command',
  },
])
  .then(console.log)
  .catch(console.error);
js
// Remove all commands
guild.commands.set([])
  .then(console.log)
  .catch(console.error);

Source

edit

async

async edit(command: ApplicationCommandResolvable, data: Partial<ApplicationCommandDataResolvable>, guildId?: Snowflake): Promise<ApplicationCommand>

Edits an application command. Parameters

NameTypeDescription
commandApplicationCommandResolvableThe command to edit
dataPartial<ApplicationCommandDataResolvable>The data to update the command with
guildId?SnowflakeThe guild's id where the command registered,
ignored when using a GuildApplicationCommandManager

Returns: Promise<ApplicationCommand>

js
// Edit an existing command
client.application.commands.edit('123456789012345678', {
  description: 'New description',
})
  .then(console.log)
  .catch(console.error);

Source

delete

async

async delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<?ApplicationCommand>

Deletes an application command. Parameters

NameTypeDescription
commandApplicationCommandResolvableThe command to delete
guildId?SnowflakeThe guild's id where the command is registered,
ignored when using a GuildApplicationCommandManager

Returns: Promise<?ApplicationCommand>

js
// Delete a command
guild.commands.delete('123456789012345678')
  .then(console.log)
  .catch(console.error);

Source

resolve

resolve(idOrInstance: string | Object): Object

Resolves a data entry to a data Object. Parameters

NameTypeDescription
idOrInstancestring | ObjectThe id or instance of something in this Manager

Returns: Object — An instance from this Manager Source

resolveId

resolveId(idOrInstance: string | Object): Snowflake

Resolves a data entry to an instance id. Parameters

NameTypeDescription
idOrInstancestring | ObjectThe id or instance of something in this Manager

Returns: SnowflakeSource

transformCommand

static · private

transformCommand(command: ApplicationCommandDataResolvable): APIApplicationCommand

Transforms an ApplicationCommandData object into something that can be used with the API. Parameters

NameTypeDescription
commandApplicationCommandDataResolvableThe command to transform

Returns: APIApplicationCommandSource

Unofficial software. Not affiliated with or supported by Discord.