Skip to content

Latest commit

 

History

History
585 lines (326 loc) · 20.2 KB

File metadata and controls

585 lines (326 loc) · 20.2 KB

Bot / structs/commands/ContextCommand / ContextCommand

Class: ContextCommand<T>

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

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

Type parameters

Name Type Description
T extends ApplicationCommandType.Message | ApplicationCommandType.User The type of context command the structure represents.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new ContextCommand<T>(handler)

Initializes a new Module instance.

Type parameters

Name Type
T extends User | Message

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


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<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.

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


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 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

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

Overrides

BaseCommand.type

Defined in

src/structs/commands/ContextCommand.ts:28


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 the command is invoked by a user through the respective context menu, it is responsible for executing the command's logic.

Parameters

Name Type Description
interaction T extends Message ? MessageContextMenuCommandInteraction<CacheType> : UserContextMenuCommandInteraction<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/ContextCommand.ts:40


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 T extends Message ? MessageContextMenuCommandInteraction<CacheType> : UserContextMenuCommandInteraction<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/ContextCommand.ts:53


toJSON

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.

Returns

T extends Message ? Explicit<MessageApplicationCommandData> : Explicit<UserApplicationCommandData>

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/ContextCommand.ts:67