RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-command

error-invalid-command

Error message

Invalid Command Provided

What it means

The 'slashCommand' method throws error-invalid-command when command.cmd is falsy or the name is absent from the global slashCommands.commands registry (no command registered under that name with a callback). Commands register server-side via slashCommands.add (core) or through the Apps Engine (apps). Note the error details carry a stale method name ('executeSlashCommandPreview') — a copy-paste artifact in the source.

Source

Thrown at apps/meteor/server/lib/utils/slashCommand.ts:153

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		slashCommand(params: { cmd: string; params: string; msg: IMessage; triggerId: string }): unknown;
	}
}

Meteor.methods<ServerMethods>({
	async slashCommand(command) {
		methodDeprecationLogger.method('slashCommand', '9.0.0', '/v1/commands.run');
		const userId = Meteor.userId();
		if (!userId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'slashCommand',
			});
		}

		if (!command?.cmd || !slashCommands.commands[command.cmd]) {
			throw new Meteor.Error('error-invalid-command', 'Invalid Command Provided', {
				method: 'executeSlashCommandPreview',
			});
		}

		return slashCommands.run({
			command: command.cmd,
			params: command.params,
			message: command.msg,
			triggerId: command.triggerId,
			userId,
		});
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the exact registered command name (inspect its slashCommands.add registration, or GET /api/v1/commands.list for commands available to the user).
  2. Re-enable or reinstall the app/module that provides the command.
  3. For custom commands, make sure slashCommands.add ran on the server before invocation.
  4. Send cmd consistently without the leading '/' (the UI strips it before dispatch).

Example fix

// before: typo'd / unregistered name
Meteor.call('slashCommand', { cmd: 'gimmeA', params: 'cat', msg });

// after: exact registered name, no leading slash
Meteor.call('slashCommand', { cmd: 'gimme', params: 'cat', msg });
Defensive patterns

Strategy: validation

Validate before calling

// Server-side: confirm the command is registered before dispatching
const isRegisteredCommand = (cmd: string): boolean =>
  Boolean(cmd && slashCommands.commands[cmd] && typeof slashCommands.commands[cmd].callback === 'function');

Try / catch

try {
  await Meteor.callAsync('slashCommand', { cmd, params, msg });
} catch (err: any) {
  if (err?.error === 'error-invalid-command') {
    showWarning(`Command "${cmd}" is not available on this server`);
    await refreshAvailableCommands(); // e.g. GET /api/v1/commands.list
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Meteor.call('slashCommand', { cmd: '/unknown', ... }) for a never-registered command; invoking an app-provided slash command while the app is disabled or uninstalled; mismatched cmd casing or an unexpected leading '/' character.

Common situations: Typos in command names; app commands unavailable after the app was disabled; environments missing an app/enterprise module that provides the command; version upgrades that renamed or removed commands.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/61968e6c844fc371. Report an issue: GitHub.