Bot / structs/commands/SlashCommand / 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
-
BaseCommand<ApplicationCommandType.ChatInput>↳
SlashCommand
- category
- clientPermissions
- description
- descriptionLocalizations
- dm
- guilds
- handler
- logger
- name
- nameLocalizations
- nsfw
- options
- permissions
- type
- util
- exec
- initialize
- isContextCommand
- isMessageContextCommand
- isSlashCommand
- isUserContextCommand
- onError
- toJSON
• new SlashCommand(handler)
Initializes a new Module instance.
| Name | Type | Description |
|---|---|---|
handler |
Handler<Module> |
The handler that manages the module. |
• 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.
• 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.
src/structs/commands/BaseCommand.ts:90
• 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.
src/structs/commands/BaseCommand.ts:40
• 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
src/structs/commands/SlashCommand.ts:32
• 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.
src/structs/commands/BaseCommand.ts:98
• 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
src/structs/commands/BaseCommand.ts:118
• 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.
• 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
• Readonly Abstract name: string
The module's name.
This will represent how the module is referenced within the handler and possible error messages.
• 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
src/structs/commands/BaseCommand.ts:61
• 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
src/structs/commands/BaseCommand.ts:108
• 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
src/structs/commands/SlashCommand.ts:58
• 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
- https://discord.com/developers/docs/interactions/slash-commands#permissions
- https://discordjs.guide/slash-commands/permissions.html#member-permissions
src/structs/commands/BaseCommand.ts:78
• 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
src/structs/commands/SlashCommand.ts:43
• 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.
▸ 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.
| Name | Type | Description |
|---|---|---|
interaction |
ChatInputCommandInteraction<CacheType> |
The interaction that invoked the command. |
Promise<InteractionResponse>
The response to send to the interaction.
src/structs/commands/SlashCommand.ts:69
▸ 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.
void
▸ isContextCommand(): this is ContextCommand<User> | ContextCommand<Message>
Indicates whether if the command is a context command.
this is ContextCommand<User> | ContextCommand<Message>
Whether if the command is a context command.
src/structs/commands/BaseCommand.ts:192
▸ isMessageContextCommand(): this is ContextCommand<Message>
Indicates whether if the command is a message context command.
this is ContextCommand<Message>
Whether if the command is a message context command.
BaseCommand.isMessageContextCommand
src/structs/commands/BaseCommand.ts:210
▸ isSlashCommand(): this is SlashCommand
Indicates whether if the command is a slash command.
this is SlashCommand
Whether if the command is a slash command.
src/structs/commands/BaseCommand.ts:183
▸ isUserContextCommand(): this is ContextCommand<User>
Indicates whether if the command is a user context command.
this is ContextCommand<User>
Whether if the command is a user context command.
BaseCommand.isUserContextCommand
src/structs/commands/BaseCommand.ts:201
▸ 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.
| Name | Type | Description |
|---|---|---|
interaction |
ChatInputCommandInteraction<CacheType> |
The interaction that invoked the command. |
error |
Error |
The error that was thrown. |
Promise<InteractionResponse>
The response to send to the interaction.
src/structs/commands/SlashCommand.ts:82
▸ 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.
Explicit<ChatInputApplicationCommandData>
The base information regarding the command serialized into a JSON
See