Skip to content

Latest commit

 

History

History
623 lines (348 loc) · 21.5 KB

File metadata and controls

623 lines (348 loc) · 21.5 KB

Bot / structs/commands/SlashCommand / SlashCommand

Class: SlashCommand

structs/commands/SlashCommand.SlashCommand

The base structure for slash commands.

Slash commands are a type of application command, they are Discord's own implementation of commands. They provide a variety of features that are not present when using commands simply as messages.

Slash commands are an essential part of a Discord application, they allow users to interact with the application in variety of ways. They are invoked by typing / in a channel or DM, selecting the desired command from the autocomplete menu.

See

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

Hierarchy

  • BaseCommand<ApplicationCommandType.ChatInput>

    SlashCommand

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new SlashCommand(handler)

Initializes a new Module instance.

Parameters

Name Type Description
handler Handler<Module> The handler that manages the module.

Inherited from

BaseCommand.constructor

Defined in

src/structs/Module.ts:69

Properties

category

Readonly category: string = 'default'

The category that the module belongs to.

Modules are pieces of functionality that are grouped together, however, modules can further be grouped together. This property can be used to group modules together within the handler.

For example, commands are pieces of modules that can be represented through the Module class. In addition, modules can be grouped together by their purpose, such as administration commands or music commands.

Inherited from

BaseCommand.category

Defined in

src/structs/Module.ts:36


clientPermissions

Optional Readonly clientPermissions: ("CreateInstantInvite" | "KickMembers" | "BanMembers" | "Administrator" | "ManageChannels" | "ManageGuild" | "AddReactions" | "ViewAuditLog" | "PrioritySpeaker" | "Stream" | "ViewChannel" | "SendMessages" | "SendTTSMessages" | "ManageMessages" | "EmbedLinks" | "AttachFiles" | "ReadMessageHistory" | "MentionEveryone" | "UseExternalEmojis" | "ViewGuildInsights" | "Connect" | "Speak" | "MuteMembers" | "DeafenMembers" | "MoveMembers" | "UseVAD" | "ChangeNickname" | "ManageNicknames" | "ManageRoles" | "ManageWebhooks" | "ManageEmojisAndStickers" | "ManageGuildExpressions" | "UseApplicationCommands" | "RequestToSpeak" | "ManageEvents" | "ManageThreads" | "CreatePublicThreads" | "CreatePrivateThreads" | "UseExternalStickers" | "SendMessagesInThreads" | "UseEmbeddedActivities" | "ModerateMembers" | "ViewCreatorMonetizationAnalytics" | "UseSoundboard" | "UseExternalSounds" | "SendVoiceMessages")[]

Permissions the client needs in order to execute the command.

This property differs from the permissions property as it is in regards to the client itself. If specified, the client will check that it has all provided permissions before executing the command.

If the client is missing any of the provided permissions, the command will not be executed.

Inherited from

BaseCommand.clientPermissions

Defined in

src/structs/commands/BaseCommand.ts:90


description

Readonly Abstract description: string

The command's description.

An in-depth description of the command, this property should present a thorough description of the command and its functionality.

Inherited from

BaseCommand.description

Defined in

src/structs/commands/BaseCommand.ts:40


descriptionLocalizations

Optional Readonly descriptionLocalizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "sv-SE" | "th" | "tr" | "uk" | "vi", null | string>>

Localization dictionary for the command's name.

Represents the localization dictionary for the command's description, which will cause the application to use the localcized description dependent on the client's selected language.

See

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

Defined in

src/structs/commands/SlashCommand.ts:32


dm

Optional Readonly dm: boolean

Indicates whether if the command is available within the client's DMs.

This flag is only applicable for globally-scoped commands, it is ignored for guild-specific commands.

Inherited from

BaseCommand.dm

Defined in

src/structs/commands/BaseCommand.ts:98


guilds

Optional Readonly guilds: string[]

The guilds to restrict the command to.

If specified, the command will be deployed only the specified guilds, meaning the command will not be available globally.

See

https://discord.com/developers/docs/interactions/slash-commands#registering-a-command

Inherited from

BaseCommand.guilds

Defined in

src/structs/commands/BaseCommand.ts:118


handler

Readonly handler: Handler<SlashCommand>

A reference to the handler that manages this module.

This property references the handler that manages the module, allowing the module to access the Discord client and other modules within the handler.

Inherited from

BaseCommand.handler

Defined in

src/structs/Module.ts:62


logger

Readonly logger: Logger = logger

The logging system.

A useful logging system that prints messages in a structured format, all logs are additionally stored in a file for future reference.

See

https://github.com/norviah/logger

Inherited from

BaseCommand.logger

Defined in

src/structs/Module.ts:46


name

Readonly Abstract name: string

The module's name.

This will represent how the module is referenced within the handler and possible error messages.

Inherited from

BaseCommand.name

Defined in

src/structs/Module.ts:23


nameLocalizations

Optional Readonly nameLocalizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "sv-SE" | "th" | "tr" | "uk" | "vi", null | string>>

Localization dictionary for the command's name.

Represents the localization dictionary for the command's name, which will cause the application to use the localcized name dependent on the client's selected language.

See

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

Inherited from

BaseCommand.nameLocalizations

Defined in

src/structs/commands/BaseCommand.ts:61


nsfw

Optional Readonly nsfw: boolean

Indicates whether if the command should be age-restricted.

Commands that contains age-restricted content should be marked as such, this will limit who can see and access the command.

See

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

Inherited from

BaseCommand.nsfw

Defined in

src/structs/commands/BaseCommand.ts:108


options

Optional Readonly options: ApplicationCommandOptionData[]

Any options for the command.

Commands may have options, which can be thought of as arguments to a function, these provide a way for the user to provide additional information the command may need.

When the command is called, the user will be prompted to provide these options, in addition to any auto-completion that may be provided - such as a list of channels.

See

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure

Defined in

src/structs/commands/SlashCommand.ts:58


permissions

Optional Readonly permissions: ("CreateInstantInvite" | "KickMembers" | "BanMembers" | "Administrator" | "ManageChannels" | "ManageGuild" | "AddReactions" | "ViewAuditLog" | "PrioritySpeaker" | "Stream" | "ViewChannel" | "SendMessages" | "SendTTSMessages" | "ManageMessages" | "EmbedLinks" | "AttachFiles" | "ReadMessageHistory" | "MentionEveryone" | "UseExternalEmojis" | "ViewGuildInsights" | "Connect" | "Speak" | "MuteMembers" | "DeafenMembers" | "MoveMembers" | "UseVAD" | "ChangeNickname" | "ManageNicknames" | "ManageRoles" | "ManageWebhooks" | "ManageEmojisAndStickers" | "ManageGuildExpressions" | "UseApplicationCommands" | "RequestToSpeak" | "ManageEvents" | "ManageThreads" | "CreatePublicThreads" | "CreatePrivateThreads" | "UseExternalStickers" | "SendMessagesInThreads" | "UseEmbeddedActivities" | "ModerateMembers" | "ViewCreatorMonetizationAnalytics" | "UseSoundboard" | "UseExternalSounds" | "SendVoiceMessages")[]

Default permissions for the command.

Note that these permissions represent the default permissions for the command when the command is first deployed to a guild or when the application joins a new guild.

These permissions are only the default and can be altered by guild administrators, allowing them to configure access however they see fit. Due to this, it is highly advised to not implement commands that are dev-only which use actions such as eval.

See

Inherited from

BaseCommand.permissions

Defined in

src/structs/commands/BaseCommand.ts:78


type

Readonly type: ChatInput = ApplicationCommandType.ChatInput

The type of command.

This property informs Discord the of the command's type, allowng them to provide the command to the user in the correct context. As this command represents a slash command, the type is set to CHAT_INPUT.

See

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types

Overrides

BaseCommand.type

Defined in

src/structs/commands/SlashCommand.ts:43


util

Readonly util: ModuleUtil

A collection of helpful methods for the module.

This property references a collection of helpful methods that can be used by the module.

Inherited from

BaseCommand.util

Defined in

src/structs/Module.ts:54

Methods

exec

Abstract exec(interaction): Promise<InteractionResponse>

The command's execution method.

This method is called when a user calls the command in Discord, it is responsible for executing the command's logic.

Parameters

Name Type Description
interaction ChatInputCommandInteraction<CacheType> The interaction that invoked the command.

Returns

Promise<InteractionResponse>

The response to send to the interaction.

Overrides

BaseCommand.exec

Defined in

src/structs/commands/SlashCommand.ts:69


initialize

Optional initialize(): void

Further initialization logic for the module after it has been imported by the handler.

Once the handler has imported and initialized all modules, this method is called on each module. If desired, this method can be implemented to further initialize the module once imported.

Returns

void

Inherited from

BaseCommand.initialize

Defined in

src/structs/Module.ts:85


isContextCommand

isContextCommand(): this is ContextCommand<User> | ContextCommand<Message>

Indicates whether if the command is a context command.

Returns

this is ContextCommand<User> | ContextCommand<Message>

Whether if the command is a context command.

Inherited from

BaseCommand.isContextCommand

Defined in

src/structs/commands/BaseCommand.ts:192


isMessageContextCommand

isMessageContextCommand(): this is ContextCommand<Message>

Indicates whether if the command is a message context command.

Returns

this is ContextCommand<Message>

Whether if the command is a message context command.

Inherited from

BaseCommand.isMessageContextCommand

Defined in

src/structs/commands/BaseCommand.ts:210


isSlashCommand

isSlashCommand(): this is SlashCommand

Indicates whether if the command is a slash command.

Returns

this is SlashCommand

Whether if the command is a slash command.

Inherited from

BaseCommand.isSlashCommand

Defined in

src/structs/commands/BaseCommand.ts:183


isUserContextCommand

isUserContextCommand(): this is ContextCommand<User>

Indicates whether if the command is a user context command.

Returns

this is ContextCommand<User>

Whether if the command is a user context command.

Inherited from

BaseCommand.isUserContextCommand

Defined in

src/structs/commands/BaseCommand.ts:201


onError

onError(interaction, error): Promise<InteractionResponse>

Invoked if the command throws an error during execution.

During the execution of the command, if an error is thrown, this method is then called. This method should be implemented to handle the error and generate a response, which will be sent to the user.

Parameters

Name Type Description
interaction ChatInputCommandInteraction<CacheType> The interaction that invoked the command.
error Error The error that was thrown.

Returns

Promise<InteractionResponse>

The response to send to the interaction.

Overrides

BaseCommand.onError

Defined in

src/structs/commands/SlashCommand.ts:82


toJSON

toJSON(): Explicit<ChatInputApplicationCommandData>

The command serialized into a JSON object.

When deploying a command to Discord, we'll need to send a JSON payload describing the command, this method serializes the information of the command into a JSON object.

Returns

Explicit<ChatInputApplicationCommandData>

The base information regarding the command serialized into a JSON

See

https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-structure

Overrides

BaseCommand.toJSON

Defined in

src/structs/commands/SlashCommand.ts:96