Skip to main content

Parameters

You can build your command parameters in a easy way using the ParamsBuilder class.

ParamsBuilder methods.

  • .addAttachment(options)
  • .addBoolean(options)
  • .addChannel(options)
  • .addMember(options)
  • .addNumber(options)
  • .addRole(options)
  • .addString(options)

Interfaces

// Any other param that differs from string and number.
interface BaseParam {
/** The name for this parameter. */
name: string
/** The description for this parameter. */
description: string
/** Mark this param as required or not. */
required: boolean
/** Parameter type. (if needed) */
type?: ApplicationCommandOptionType
/** Parameter default value. */
value?: any
/** Mostly to be used for string. Return all arguments after this parameter (including this one) */
ellipsis?: boolean
}

interface StringParam extends BaseParam {
/** String choices. */
choices?: { name: string, value: string }[]
/** Maximum string length. */
max_length?: number
/** Minimum string length. */
min_length?: number
}

interface NumberParam extends BaseParam {
/** Maximum number length. */
max_value?: number
/** Minimum string length. */
min_value?: number
/** Number choices. */
choices?: { name: string, value: string }[]
}

interface ChannelParam extends BaseParam {
/** An array of allowed channel types. */
channel_types?: ChannelType[]
}

Example

const { CommandBuilder, ParamsBuilder } = require('erine');

const data = {
data: new CommandBuilder({
name: "say",
as_prefix: true,
as_slash: true
}),
params: new ParamsBuilder()
.addString({
name: 'message',
description: 'The message to say.',
required: true,
ellipsis: true,
max_length: 1000
}),
async code(context) {
const message = context.get('message'); // We can get the parameters using this way.
await context.send(message);
}
}