command() declares a slash command, from any file of src/; its name is what people type after the /. It takes one object, CommandConfig, and types run from it. With a type, it declares a menu command instead, used with a right click on a message or a person.
src/commands/ping.ts
How to write a command, its options, its answers and its translations is in the guide, and menu commands in their own page. This page lists what exists.
command()
src/.
A slash command: name is what people type after the / ('mod ban' for /mod ban). A menu command, with type: used with a right click on a message ('message') or on a person ('user'), name being what the menu shows.
Options, Where and Type are inferred from what you pass: you never write them.
CommandDeclaration
command() returns: a declaration the framework finds in the exports of a file. It keeps the options and the place the file declared.
CommandConfig
What a file gives tocommand(): what the command is and does.
What people type after the
/: 'ping' is /ping. A subcommand is written with its parents: 'mod ban' is /mod ban, 'mod roles add' is /mod roles add.What the command does, shown under its name (1-100 characters). Here, with
locales for its translations; or left out, and every text of the command (description, options, their choices, translations) comes from the language files of the project. One or the other.What to do when someone uses the command.
The command in other languages: Discord shows each person the names and descriptions of their language. Your code always receives the names declared above, whatever the language.Discord documentation
The permissions a member needs to use the command. Server admins can change who sees it in the server settings.
Where the command can be used:
'guild' (in servers, the default), 'dm' (in private messages with the bot) or 'both'. What run receives follows it.How long to wait before the command can be used again:
'10s' for each person, or { user, channel, guild } for each place. Someone who uses it too soon gets a private answer saying when they can.Suggestions that come from your bot while the person types, for the options named here (a
string, integer or number option without choices): each function receives what they typed and returns the suggestions. The person may still type something else.Leave it out for a slash command.
'message' or 'user' makes a menu command instead, used with a right click on a message or a person.CommandName
- and _, 32 characters at most ('ping'). A subcommand is written with its parents, separated by spaces: 'mod ban' is /mod ban, 'mod roles add' is /mod roles add (Discord allows nothing deeper).
CommandWhere
'guild'), in private messages with the bot ('dm'), or in both.
Discord documentation
Cooldown
user for each person, channel for each channel, guild for each server (not for a command of private messages). Someone who uses it too soon gets a private answer saying when they can, and run does not run.
Duration
s, m, h or d, like '30s', '10m', '2h', '1d'. Several parts add up: '1h30m'.
The options
CommandOptions
- and _, 32 characters at most.
CommandOption
The kind of option:
'string', 'integer', 'number', 'boolean', 'user', 'role', 'channel', 'mentionable' or 'attachment'.What the option is for, shown under its name (1-100 characters). Here when the command has its
description here; otherwise in the default language file of the project.StringOption
A text the user types, or picks amongchoices.
The only values the user can pick (25 at most): a list, or an object whose keys are what the user sees and values what your code receives.
NumberOption
A whole number (integer) or any number (number).
The only values the user can pick (25 at most): a list, or an object whose keys are what the user sees and values what your code receives.
'integer' option, min, max and the choices must be whole numbers.
ChannelOption
A channel the user picks.The kinds of channels that can be picked. By default, all of them. The values are those of
ChannelType.SimpleOption
True or false, a user, a role, a user or a role, or a file.The kind of option: what the user picks.
OptionValuesOf
undefined. It is the type of options in run.
With
choices, the value is the union of the choices: 'red' | 'green' for choices: ['red', 'green'], 1 | 2 for choices: { Small: 1, Large: 2 }.
Autocomplete
CommandAutocomplete
autocomplete of a command: one function per option whose suggestions come from your bot while the person types, by the name of the option. Only a string, integer or number option without choices can have one. The function returns the suggestions (25 at most, Discord shows them in that order), or a promise of them: Discord waits 3 seconds. The person may still type something else.
Value is string for a string option, number | undefined for an integer or number option in the context, and string or number in the suggestions. When no option can have suggestions, no key is accepted, and the editor says why.
Discord documentation
AutocompleteContext
autocomplete function receives, each time the person types in its option. Nothing of it can be answered: the suggestions are what the function returns.
What the person has typed so far in the option: a text, maybe empty, for a
string option; for an integer or number option, a number, or undefined while what they typed is not one yet.The texts of the project in the language of the person, when the project has a language. See
Translator.where, like CommandContext without its interaction: in a server guild, member and channel (CommandInGuild); in private messages only channel (CommandInDm); with 'both', if (guild) tells which one it is (CommandInPrivate).
OptionsSoFar
user, role, channel, mentionable or attachment option is its id.
Suggestion
{ name, value } to show a text (1-100 characters) and receive another value. The value is a text (100 characters at most) for a string option, a number for an integer or number option.
What run receives
CommandContext
run function of a command receives. It follows where: in a server, the server, the member and the channel are there; in private messages they do not exist; in both, if (guild) tells which one it is, for everything at once.
Whatever where says, it has:
The texts of the language files, in the right language. Only when the project has a language: see
TranslationContext.where:
CommandInGuild
What a command used in a server receives about where it was used.CommandInDm
What a command only used in private messages receives: no server.CommandInPrivate
What a command that works in both places receives when it is used in a private message:guild is null, and checking it tells the rest.
The interactions themselves are described in Interaction.
Translations
CommandLocales
Locale: fr, de, es-ES…
CommandTranslation
The translation of a command in one language. Everything is optional: what is not translated is shown as declared.The translation of each option, by the name declared in
options.OptionTranslation
The translation of one option. Everything is optional.What each choice is called in that language. The keys are the choices as declared: the values of a list, or the keys of an object. Each value is 1 to 100 characters.
Menu commands
src/commands/quote.ts
MenuType
'message') or a person ('user').
Discord documentation
MenuConfig
command() for a menu command: one used on a message or a person, from the menu of a right click. It has no description and no options: what it receives is what it was used on.
What the command is used on:
'message' (a right click on a message) or 'user' (a right click on a person).What the menu shows (1-32 characters): capitals and spaces are fine, like
'Report message'.The name in other languages: Discord shows each person the name of their language.Discord documentation
The permissions a member needs to use the command. Server admins can change who sees it in the server settings.
Where the command can be used:
'guild' (in servers, the default), 'dm' (in private messages with the bot) or 'both'. What run receives follows it.How long to wait before the command can be used again:
'10s' for each person, or { user, channel, guild } for each place.MenuDeclaration
command() returns for a menu command.
MenuContext
run function of a menu command receives: what it was used on (message, or target and targetMember), who used it, and the place, which follows where like the one of a slash command (CommandInGuild, CommandInDm, CommandInPrivate).
With
type: 'message': the message the menu was used on. A GuildMessage in a server, a PrivateMessage in a private message of a where: 'both' command, a DmMessage with where: 'dm'.With
type: 'user', in a server: that person as a member of the server, or null when they are not in it (any more). null in a private message; absent with where: 'dm'.The texts of the language files, in the right language. Only when the project has a language: see
TranslationContext.MenuLocales
MenuTranslation
The translation of a menu command in one language: its name.The limits
What a file declares is checked when it loads, against the limits of Discord, with a message that says what to write:
Discord documentation