Message Command Flags
Reciple provides support for message command flags. This flags are used similar to CLI flags.
Simple String Flag
import { MessageCommandBuilder } from 'reciple';
new MessageCommandBuilder()
.setName('test')
.setDescription('A test command')
.addFlag(flag => flag
.setName('flag')
.setShortcut('f')
.setDescription('A test flag')
.setValueType('string')
.setRequired(true)
)
.setExecute(async ({ message, flags }) => {
const flag = flags.getFlagValues('flag', { required: true })[0];
await message.reply(`Received: **${flag}**`);
})
Command Usage
Boolean Flag
import { MessageCommandBuilder } from 'reciple';
new MessageCommandBuilder()
.setName('test')
.setDescription('A test command')
.addFlag(flag => flag
.setName('flag')
.setShortcut('f')
.setDescription('A test flag')
.setValueType('boolean')
.setRequired(true)
)
.setExecute(async ({ message, flags }) => {
const flag = flags.getFlagValues('flag', { required: true })[0];
await message.reply(`Received: **${flag}**`);
})
Command Usage
Validate & Resolve Command Flag Values
You make your own flag value validator and Resolver by using MessageCommandFlagBuilder#setValidator()
and MessageCommandFlagBuilder#setresolvevalue()
import { MessageCommandBuilder } from 'reciple';
new MessageCommandBuilder()
.setName('test')
.setDescription('A test command')
.addFlag(flag => flag
.setName('flag')
.setShortcut('f')
.setDescription('A test flag')
.setValueType('string')
.setRequired(true)
.setMultiple(true)
.setResolveValue(({ values }) => values.map(v => Number(v)))
.setValidator(({ values }) => values.every(v => !isNaN(Number(v))))
)
.setExecute(async ({ message, flags }) => {
const flag = await flags.getFlagValues('flag', { required: true, resolveValue: true });
await message.reply(`Received: **${flag.join(', ')}**`);
})
INFO
When using
setResolveValue
, you must use MessageCommandFlagManager#getFlagValues()
with the resolveValue
flag set to true
. This will make the return values of the flag a Promise
of the resolved value.