Command Options
On this page we will cover the different options you can use when creating a command. For each option we will cover what it does, how to use it, and what the default value is. As a reminder, a Command extends a Piece and therefore inherits all of Piece options.
For a full list of available options, refer to the CommandOptions interface.
Without further ado, lets go over all of the available options:
cooldownDelay
The time in milliseconds for the cooldown entries to reset, if set to a non-zero value alongside
cooldownLimit
, the Cooldown
precondition will be added to the list.
cooldownFilteredUsers
The users that are exempt from the Cooldown precondition. Use this to filter out someone like a bot owner
cooldownLimit
The amount of entries the cooldown can have before filling up, if set to a non-zero value alongside
cooldownDelay
, the Cooldown
precondition will be added to the list.
cooldownScope
The scope of the cooldown entries. This has to use the enum BucketScope. This can be used to set the scope of the cooldown to for example the entire server, which will mean that a command cooldown applies to all members of that server.
description
A basic summary about the command.
detailedDescription
Longer version of command's summary and how to use it. You can leverage this to more information about a command such as
usage
, examples
, extendedHelp
, etc. This can be useful for when writing a help command. If you would like to
include these custom properties you will have to module augment the
DetailedDescriptionCommandObject
interface:
declare module '@sapphire/framework' {
export interface DetailedDescriptionCommandObject {
usage: string;
examples: string[];
extendedHelp: string;
}
}
Every time you now provide the detailedDescription
option, you will have to provide all of the properties defined in
the module augmentation. You can then proceed to read these properties in your help command.
flags
The accepted flags. Flags are key-only identifiers that can be placed anywhere in the command. Two different types are accepted:
- An array of strings, e.g.
['silent']
. - A boolean defining whether the strategy should accept all keys (
true
) or none at all (false
).
The default value of this option is []
(empty array)
For more information, see the Using Flags page
fullCategory
By default this property will get resolved based on the path that the command file is in and in many cases you do not need to set this option. However, if for whatever reason you desire to customize the full category and not have it depend on the folder structure, then you can set it here.
The full category for the command. Either an array of strings that denote every (sub)folder the command is in, or null
if it could not be resolved automatically.
generateDashLessAliases
Whether to add aliases for commands without dashes in them. For example if the command name is foo-bar
and this option
is set to true, then an alias of foobar
will automatically be added.
generateUnderscoreLessAliases
Whether to add aliases for commands without underscores in them. For example if the command name is foo_bar
and this
option is set to true, then an alias of foobar
will automatically be added.
nsfw
Sets whether the command should be treated as NSFW. If set to true, the NSFW
precondition will be added to the list.
The NSFW
precondition will throw an error if the command is ran in a non-NSFW channel.
options
The accepted options. Options are key-value identifiers that can be placed anywhere in the command. Two different types are accepted:
- An array of strings, e.g. [
silent
]. - A boolean defining whether the strategy should accept all keys (
true
) or none at all (false
).
The default value of this option is []
(empty array)
For more information, see the Using Options page
preconditions
The Preconditions
to be run, accepts an array of their names.
prefixes
The available prefixes for both flags
and options
.
The default value is ['--', '-', '—']
.
quotes
The quotes accepted by this command, pass []
to disable them.
The default value is:
[
['"', '"'], // Double quotes
['“', '”'], // Fancy quotes (on iOS)
['「', '」'], // Corner brackets (CJK)
['«', '»'] // French quotes (guillemets)
];
requiredClientPermissions
The permissions the bot client requires to execute this command. Think for example if you're about to send an embed,
then your bot needs the EMBED_MESSAGES
permission. You can then add this option with the desired permission and
Sapphire will ensure the command code doesn't error and instead you'll get a precondition rejection. You can use the
common-PermissionFlagsBits enum to get the correct values.
requiredUserPermissions
The permissions the user requires to execute this command. Think for example if you have a ban
command, you'd only
want people with Administrator to use that. You can then add this option with the desired permission and Sapphire will
ensure the command code doesn't error and instead you'll get a precondition rejection. You can use the
common-PermissionFlagsBits enum to get the correct values.
runIn
The channel types in which this command can be ran.
separators
The separators for options (i.e. what separates the key from the value).
The default values are ['=', ':']
. This allows for both --key=value
and --key:value
to be valid.
typing
If the typing
option on your client is true, it can be overridden for a specific command using this property, set via
its options. Otherwise, this property will be ignored.