Kord Extensions Help

Context Commands

Context commands are a form of application command, triggered by users via a right-click/tap-and-hold menu in their Discord client. Unlike other types of command, context commands do not take arguments — instead, they're provided with whatever the user was targeting when they opened the menu.

When registered by your bot, context commands are visible in a menu named Apps. There are two types of context command — message commands and user commands. They have identical APIs, aside from the target data supplied to them by Discord.

Extension API

The following APIs are available on the Extension type, which you can use to define your context commands and modify their behavior.

Builders

Name

Receiver

Description

Checks

messageCommandCheck

CheckWithCache <MessageCommandInteractionCreateEvent>

Register a check that must pass for the action belonging to all message commands defined within this extension to be run. For more information on checks, see the dedicated documentation.

userCommandCheck

CheckWithCache <UserCommandInteractionCreateEvent>

Register a check that must pass for the action belonging to all user commands defined within this extension to be run. For more information on checks, see the dedicated documentation.

Commands

ephemeralMessageCommand

EphemeralMessageCommand

Register an ephemeral message command. This builder function optionally takes the constructor of a modal form class as the first argument, representing the modal form to display and await input for when the command is executed.

ephemeralUserCommand

EphemeralUserCommand

Register an ephemeral user command. This builder function optionally takes the constructor of a modal form class as the first argument, representing the modal form to display and await input for when the command is executed.

publicMessageCommand

PublicMessageCommand

Register a public message command. This builder function optionally takes the constructor of a modal form class as the first argument, representing the modal form to display and await input for when the command is executed.

publicUserCommand

PublicUserCommand

Register a public user command. This builder function optionally takes the constructor of a modal form class as the first argument,s representing the modal form to display and await input for when the command is executed.

Message Commands

Message commands are registered by calling the relevant functions in your extension's setup function:

  • ephemeralMessageCommand for message commands that respond ephemerally.

  • publicMessageCommand for message commands that respond publicly.

publicMessageCommand { name = "My Command" action { val target = targetMessages.first() respond { content = "Target: ${target.getJumpUrl()}" } } }

Message commands have an identical API to that which is provided by Application Commands, but message command context objects provide a targetMessages property. This property corresponds with the Discord API, which provides a list that contains the message that was being targeted when the command was executed.

Message commands support modal forms, as described in the commands overview page.

User Commands

User commands are registered by calling the relevant functions in your extension's setup function:

  • ephemeralUserCommand for user commands that respond ephemerally.

  • publicUserCommand for user commands that respond publicly.

publicUserCommand { name = "My Command" action { val target = targetUsers.first() respond { content = "Target: ${target.mention}" } } }

User commands have an identical API to that which is provided by Application Commands, but user command context objects provide a targetUsers property. This property corresponds with the Discord API, which provides a list that contains the Discord user that was being targeted when the command was executed.

User commands support modal forms, as described in the commands overview page.

Last modified: 20 November 2024