discord.js
discord.js copied to clipboard
`ApplicationCommandOptionData` type does not cover autocomplete options with min and max values
Which package is this bug report for?
discord.js
Issue description
Apparently Discord supports having both autocomplete, min_value and max_value on a given slash command option but the ApplicationCommandOptionData type provided by Discord.js does not allow the combination.
With the code sample provided below, i get the following error:
Type '{ type: "INTEGER"; name: string; description: string; required: true; min_value: number; max_value: number; autocomplete: true; }' is not assignable to type 'ApplicationCommandOptionData'. Object literal may only specify known properties, and 'min_value' does not exist in type 'ApplicationCommandAutocompleteOption'.
Here is my use case: i have a command with one option of type INTEGER that displays the item at the given index in a well-known array that contains objects. Since the integer has to be a valid index, i basically put 0 as the min value and length - 1 as the max value. But now i want to enable autocomplete: the user can type strings and let the bot finds the best matching items and suggests a list of indices. Discord displays the name and not the value so i can put whatever string i want as the name and the index as the value and the user will not directly see the actual index (until the command is submitted).
This makes sure the option value the user sends is always a valid index, while having the autocomplete experience with strings.
It would be useful to update the type so it can enable this use case for TypeScript users.
Code sample
const items: {name: string}[] = [{name: "A"}, {name: "B"}, {name: "C"}];
const options: ApplicationCommandOptionData[] = [
{
type: "INTEGER",
name: "Item",
description: "Some item",
required: true,
min_value: 0,
max_value: items.length - 1,
autocomplete: true,
},
];
Package version
13.8.1
Node.js version
16.15.0
Operating system
No response
Priority this issue should have
Low (slightly annoying)
Which partials do you have configured?
Not applicable (subpackage bug)
Which gateway intents are you subscribing to?
Not applicable (subpackage bug)
I have tested this issue on a development release
No response
This did not exist when this version was released. The library doesn't update to Discord's new features magically. This is a feature request - not a bug.
Is this already fixed? https://github.com/discordjs/discord.js/blob/aac8acc22be7d7af99933ef099eca7deda43cb40/packages/discord.js/typings/index.d.ts#L3824-L3827 https://github.com/discordjs/discord.js/blob/aac8acc22be7d7af99933ef099eca7deda43cb40/packages/discord.js/src/structures/ApplicationCommand.js#L220-L223