Skip to content
Entity Info commandName

$commandName

The $commandName function returns the name of the command currently being executed, as stored for the bot.

Syntax

$commandName

Parameters

None (passing one is an error).

Return value

  • Type: String
  • The name of the command (e.g., help, ban, ping), taken from the invocation metadata (command.name, or commandName).
  • If the execution has no command metadata, the error Invocation metadata command.name is unavailable. is raised.

Behavior

  • Returns the stored name of the command, not the trigger actually typed (an alias or a prefix does not change it).
  • Useful for logs, contextual help, and detection.

Examples

Execution log

$log[📌 $userName ($authorID) executed /$commandName in #$channelName[$channelID] on $serverName]

Contextual help

$title[❓ Help: $commandName]
$description[
**Command:** $commandName
**Type:** $commandType
**Folder:** $commandFolder
**Trigger:** $commandTrigger
]
$footer[Used by $userName]

Custom error handling

$if[$message[1]==]
  $sendMessage[❌ Correct usage: $commandTrigger <parameter>
  Type `!help $commandName` for more information.]
  $stop
$endif

Usage statistics (via storage)

$var[count;$getVar[usage_$commandName]]
$var[count;$calculate[$var[count]+1]]
$setVar[usage_$commandName;$var[count]]
$log[📊 $commandName used $var[count] times]

Detection for specific behavior

$if[$commandName==help]
  $sendMessage[📚 Here is the command list...]
$elseif[$commandName==ping]
  $sendMessage[🏓 Pong! Latency: $ping ms]
$else
  $sendMessage[Command $commandName executed.]
$endif

Notes

  • $commandName returns the internal name, not the trigger (prefix).
  • For the type of invocation, use $commandType.
  • For the folder, use $commandFolder.

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.