cmd.message.argument

Warning

cmd.message.argument was created in one of the early test versions of syntx.js. It will not be removed, but it can be considered obsolete.

Returns a specific word from a prefix command message by its position. Words are split by spaces, and the prefix itself is excluded from the count.

JavaScript
const { cmd } = require("syntx.js");

cmd.message.argument(index, message);

Parameters

ParameterTypeRequiredDescription
indexnumberYes0-based position of the word to retrieve, starting after the command name.
messagediscord.js MessageYesThe message object from the event.

Returns

string | null : The word at the given index, or null if no word exists at that position.

Example

For a message !ban @user spamming, index 0 is the command name (ban), index 1 is @user, and index 2 is spamming:

JavaScript
client.command({
  name: "ban",
  content: (message) => {
    const target = cmd.message.argument(1, message);
    const reason = cmd.message.argument(2, message);

    if (!target) return message.reply("Please specify a user.");
    message.reply(`Banning ${target} for: ${reason ?? "no reason provided"}`);
  },
});

Note

Index 0 is the command name itself (e.g. ban). Arguments passed by the user start at index 1.

Warning

This function throws a SyntxError if the message does not start with the configured prefix. Make sure it is only called inside client.command() handlers.