Entity Info
commandType
$commandType
The $commandType function returns the type of invocation of the command currently being executed.
Syntax
$commandType
Parameters
None (passing one is an error).
Return value
- Type: String
- For a Discord application command, the type of the command:
chatInput(a slash command),user(user context menu) ormessage(message context menu). It comes from the context variablecommandType(orcommand.type) set when the interaction is received. textwhen the context has no command type and no interaction (for example a command typed with the bot prefix).slashonly in the unusual case where the context has an interaction ID but no command type.
Behavior
- A slash command therefore gives
chatInput, notslash; a prefix command givestext, notprefix. - To test whether the command was started by a slash command,
$isSlashis the dedicated function.
Examples
Adaptive response
$if[$commandType==chatInput]
$ephemeral
✅ Operation successful!
$else
$sendMessage[✅ Operation successful!]
$endif
Differentiated log
$if[$commandType==chatInput]
$log[🔹 SLASH /$commandName by $username]
$else
$log[🔸 TEXT $commandTrigger by $username]
$endif
Contextual help
$title[⚙️ Command details]
$addField[Name;$commandName;yes]
$addField[Trigger;$commandTrigger;yes]
$var[kind;🔸 Text]
$if[$commandType==chatInput]
$var[kind;🔹 Slash]
$endif
$addField[Type;$var[kind];yes]
$addField[Folder;$commandFolder;yes]
$footer[Language: $scriptLanguage]
Hybrid command with arguments
$c[Retrieve arguments based on the type]
$if[$commandType==chatInput]
$var[arg1;((opts.target))]
$var[arg2;((opts.reason))]
$else
$var[arg1;$message[1]]
$var[arg2;$message[2]]
$endif
🎯 Target: $var[arg1] | Reason: $var[arg2]
Related functions
- $isSlash — check if the command was triggered via slash command
- Execution model — options variables and command execution
Notes
- Possible values:
chatInput,user,message(application commands),text(no interaction), orslash(interaction without command type). - For a simple boolean check, use
$isSlash, which reads a different context value (interaction.isSlash). - The value describes the invocation, not the configuration of the command: a hybrid command gives
chatInputwhen used as a slash command andtextwhen typed with the prefix.
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.