meshcore.js
Commands

Declaring a command

The trigger rule, the builder chain, aliases, scope and the reserved names.

The trigger rule

In a DM the trigger is /name, with no space after the slash. @Bot name is tolerated there too. On a channel the trigger is @Bot name, with the name the radio advertises, case-insensitive, never /. This rule is fixed. Every meshcore.js bot behaves the same and there is no option to change it.

Anything else in a message is not a command and only produces messageCreate.

The builder

Chain setName, setDescription, the optional addAliases, the arguments, then setHandler. build() runs when the client validates its bricks and throws a LoadError listing every problem at once. An invalid name, a duplicate alias or a missing handler are all reported together.

commands/heard.ts
export default new CommandBuilder()
  .setName('heard')
  .setDescription('Nodes heard in the last hour')
  .addAliases('who')
  .setHandler((ctx) => ctx.reply(`${ctx.client.contacts.cache.size} contacts on the radio`));

The file sits under commands/ and exports the builder. See Bricks and loading.

Where and how often

MethodEffect
setScope('dm', 'channel')Where the command can be triggered. Both by default.
setRequiredPermissions()Permissions the author needs, all of them. Always refused on a channel, whatever the scope.
setCooldown(seconds)Delay between two runs by the same author. 0 by default.
setMaxAge(seconds)Messages queued on the radio while the bot was offline and older than this are ignored. 300 by default.

Reserved names

help, plugins and jobs belong to the built-in commands. Declaring a command or an alias with one of these names fails build().

Reference

On this page