this error only appears on certain servers but I don't know why :
Expected: expected <= 25
Received:
35
at Object.run (x/node_modules/@sapphire/shapeshift/dist/index.js:757:72)
at x/node_modules/@sapphire/shapeshift/dist/index.js:201:66
at Array.reduce (<anonymous>)
at NumberValidator.parse (x/node_modules/@sapphire/shapeshift/dist/index.js:201:29)
at SelectMenuBuilder.addOptions (x/node_modules/@discordjs/builders/dist/index.js:651:28)
at SelectMenuBuilder.addOptions (x/node_modules/discord.js/src/structures/StringSelectMenuBuilder.js:48:18)
at Object.run (x/Src/Interactions/Modals/Config.js:29:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Code :
const listedRoles = [];
interaction.guild.roles.cache.forEach(role => {
listedRoles.push({
label: role.name,
description: "Use this role.",
emoji: "➕",
value: role.id
})
});
const row = new ActionRowBuilder().addComponents(
new SelectMenuBuilder()
.setCustomId("RoleMenu")
.setPlaceholder("Select a role.") //line 29.
.addOptions(listedRoles)
)
Using discord.js v14.2.0 and node.js v19.7.0
Any idea ? Thanks.
This happens because you can only have a maximum of 25 options in a single select menu.
Since you're only displaying roles in a given server, I recommend:
RoleSelectMenuBuilder
. This one displays all roles from a server dynamically, without having to specify options. Keep in mind that said builder is not available in discord.js@14.2.0
.That way, you could just do the following, and it would work without an issue:
const row = new ActionRowBuilder().addComponents(
new RoleSelectMenuBuilder()
.setCustomId("RoleMenu")
.setPlaceholder("Select a role.")
);
You can also read more about select menus here and here. Hope this helped :)