data, who, update(). What is new is the options, and what run receives from them.
A menu with your options
Createsrc/components/pet.ts (a menu is declared with select() and exported, from any file of src/):
src/components/pet.ts
src/commands/pet.ts
value in the file: it is 'cat' | 'dog' | 'axolotl', not a string. The framework typed it from the options, so a typo in a comparison (value === 'cta') is underlined. values is the list of everything picked, for menus that allow several.
The menu has no data, so it is put in the message as is: components: [pet]. A menu takes a whole row by itself.
Three ways to write options
Up to 25 options.
min and max say how many can be picked (1 by default): with max: 3, values holds up to three, and min: 0 allows picking nothing.
Menus filled by Discord
With atype, you declare no option: Discord fills the menu with the server. 'user', 'role', 'mentionable' (users and roles) or 'channel'. values is then a list of User, Role, User | Role or Channel:
src/components/helper-role.ts
channelTypes narrows what is listed: channelTypes: [ChannelType.GuildText] shows text channels only, with ChannelType imported from chapterjs.
What a menu is shown with
Where you put the menu in a message, a second argument changes what is shown:placeholder, disabled, and defaults, what is picked when the menu appears (the values of the options, or the ids of the users, roles or channels):
src/commands/pet-default.ts
data takes it first: menu({ page: 2 }, { defaults: ['cat'] }).
Points of attention
- A menu answers like a button:
update()to change its message,reply()for a new one, within 3 seconds (the framework defers after 2). valueis the first pick,valuesall of them. Withmax: 1, they say the same thing.- An old message with a renamed export answers “This menu is not available any more.”, like a button.
Recap
- A menu is
select({ ... }), exported, withoptionsor atype. valueandvaluesare typed from the options, or are structures for atype.defaults,placeholderanddisabledare set where the menu is put in a message.
Forms
Ask for text and choices in a window that opens in Discord.
Guide: Select menus
The same, in short.