Bot / structs/commands/ContextCommand / ContextCommand
structs/commands/ContextCommand.ContextCommand
The base structure for context commands.
In a Discord application, context commands are commands that appear within
the context menu when right clicking a user or a message, within the Apps
submenu.
See
| Name | Type | Description |
|---|---|---|
T |
extends ApplicationCommandType.Message | ApplicationCommandType.User |
The type of context command the structure represents. |
-
BaseCommand<T>↳
ContextCommand
- category
- clientPermissions
- description
- dm
- guilds
- handler
- logger
- name
- nameLocalizations
- nsfw
- permissions
- type
- util
- exec
- initialize
- isContextCommand
- isMessageContextCommand
- isSlashCommand
- isUserContextCommand
- onError
- toJSON
• new ContextCommand<T>(handler)
Initializes a new Module instance.
| Name | Type |
|---|---|
T |
extends User | Message |
| 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 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<ContextCommand<T>>
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 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 Abstract type: T
The type of context the command represents.
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 context command, it's value is constricted to T.
See
src/structs/commands/ContextCommand.ts:28
• 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 the command is invoked by a user through the respective context menu, it is responsible for executing the command's logic.
| Name | Type | Description |
|---|---|---|
interaction |
T extends Message ? MessageContextMenuCommandInteraction<CacheType> : UserContextMenuCommandInteraction<CacheType> |
The interaction that invoked the command. |
Promise<InteractionResponse>
The response to send to the interaction.
src/structs/commands/ContextCommand.ts:40
▸ 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 |
T extends Message ? MessageContextMenuCommandInteraction<CacheType> : UserContextMenuCommandInteraction<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/ContextCommand.ts:53
▸ toJSON(): T extends Message ? Explicit<MessageApplicationCommandData> : Explicit<UserApplicationCommandData>
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.
T extends Message ? Explicit<MessageApplicationCommandData> : Explicit<UserApplicationCommandData>
The base information regarding the command serialized into a JSON
See