In Discord.js v14, the maximum number of options that can be shown in an autocomplete feature is still 25. It is not possible to increase this limit.
However, you can implement pagination to show more than 25 options. When the user reaches the end of the first 25 options, you can use the "deferred" response to send a message with a "next" button that allows the user to see more options. This process can then be repeated for each page of options you want to show.
Here is an example of how to implement pagination in an autocomplete command:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageActionRow, MessageButton } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('autocomplete')
.setDescription('Autocomplete command')
.addStringOption(option =>
option.setName('options')
.setDescription('Options to autocomplete from')
.setRequired(true)
.addChoices([
['Option 1', '1'],
['Option 2', '2'],
['Option 3', '3'],
['Option 4', '4'],
['Option 5', '5'],
['Option 6', '6'],
['Option 7', '7'],
['Option 8', '8'],
['Option 9', '9'],
['Option 10', '10'],
['Option 11', '11'],
['Option 12', '12'],
['Option 13', '13'],
['Option 14', '14'],
['Option 15', '15'],
['Option 16', '16'],
['Option 17', '17'],
['Option 18', '18'],
['Option 19', '19'],
['Option 20', '20'],
['Option 21', '21'],
['Option 22', '22'],
['Option 23', '23'],
['Option 24', '24'],
['Option 25', '25'],
['Option 26', '26'],
['Option 27', '27'],
['Option 28', '28'],
['Option 29', '29'],
['Option 30', '30'],
])),
async execute(interaction) {
const options = interaction.options.getString('options').split(/,\s*/);
let currentPage = 0;
const maxPages = Math.ceil(options.length / 25);
const currentOptions = options.slice(currentPage * 25, currentPage * 25 + 25);
const row = new MessageActionRow().addComponents(
currentOptions.map(o => new MessageButton()
.setCustomId(o)
.setLabel(o)
.setStyle('PRIMARY'))
);
await interaction.deferReply({ ephemeral: true });
const message = await interaction.editReply({ content: `Page ${currentPage + 1} of ${maxPages}`, components: [row] });
const collector = message.createMessageComponentCollector({
componentType: 'BUTTON',
time: 60000,
});
collector.on('collect', async i => {
if (i.customId === 'next') {
currentPage += 1;
const currentOptions = options.slice(currentPage * 25, currentPage * 25 + 25);
row.components = currentOptions.map(o => new MessageButton()
.setCustomId(o)
.setLabel(o)
.setStyle('PRIMARY'));
if (currentPage + 1 === maxPages) {
row.components.push(new MessageButton()
.setCustomId('end')
.setLabel('End')
.setStyle('DANGER'));
}
await i.update({ content: `Page ${currentPage + 1} of ${maxPages}`, components: [row] });
} else if (i.customId === 'end') {
await i.update({ content: 'End of options', components: [] });
collector.stop();
} else {
await interaction.editReply({ content: `You selected ${i.customId}`, components: [] });
collector.stop();
}
});
},
};
This command takes a comma-separated list of up to 30 options as input and shows a row of up to 25 buttons as autocomplete options. If there are more than 25 options, a "next" button is added to show the next page of options. If the last page is reached, an "end" button is shown to stop the pagination. When a button is clicked, the command replies with the selected option and stops the collector.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-09-19 11:00:00 +0000
Seen: 12 times
Last updated: Jul 27 '22
Does AsyncSelect fail to automatically update or refresh its values?
What is the process for eliminating/concealing boot options on the rEFInd bootloader display?
Can check-boxes be positioned to the left in Angular Material's mat-list options?
What is the process to turn off caching in Swagger UI?
If my data doesn't have an ID property, what alternative key options do I have?
How to create a library using IAR Embedded workbench?
How can I create dynamic menu options for a custom TinyMCE button?
How can I export a highchart graph that includes tooltips and labels?