Skip to main content

Mention Commands

Mention commands. Since they are triggered by @ mentions of the bot, the Message Content Intent is not required to use these.


Consider using Slash Commands instead of these, as it provides better discoverability to users. These still make sense in the context of debugging or developer-only tools.

import { $mentionCommand } from 'purplet';

export default $mentionCommand({
name: 'ping',
handle() {
this.showMessage('Pong! 🏓');

The object passed to $slashCommand is the MentionCommandData interface, which has these properties:

nameThe command name, may include any characters.
argsAn array of regular expressions or MentionCommandArgument objects, see the arguments section.
handle(...args)A function that is called when the command is run, with the triggering message bound to this. The arguments passed are the arguments defined by args


Unlike Slash Commands, mention commands use positional arguments, instead of named options. If args is not set, all arguments passed to the command will be passed to handle. Otherwise, message content will be matched against a defined regular expression, and then optionally transformed. In this mode, invalid arguments will cause the command not to run at all.

Command without args array
export default $mentionCommand({
name: 'action',
handle(name, rawNumber) {
const number = parseInt(rawNumber, 10);
Command with args array
export default $mentionCommand({
name: 'action',
args: [
match: /[0-9]+/,
parse: match => parseInt(match[0]),
handle(name, number) {
// name is a string, number is a number

Built-in argument matchers

Purplet provides a couple of MentionCommandArgument objects you can reuse for common purposes. They are exported as the ArgTypes object, which includes the following:

stringstringMatches any input.
alphanumericstringMatches any alphanumeric character.
numbernumberMatches any number.
booleanbooleanMatches true, false, yes, no, and other variations.
integernumberMatches any integer number.
snowflakestringMatches any Discord snowflake.