Error when creating a button and a menu through a function

Hello, I get this error:
DiscordAPIError[50035]: Invalid Form Body
components[0].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 1521 in length.
components[1].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 1521 in length.
at handleErrors (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async InteractionWebhook.editMessage (C:\Kigo-2\node_modules\discord.js\src\structures\Webhook.js:338:15)
at async StringSelectMenuInteraction.editReply (C:\Kigo-2\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:158:17)
DiscordAPIError[50035]: Invalid Form Body
components[0].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 1521 in length.
components[1].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 1521 in length.
at handleErrors (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (C:\Kigo-2\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async InteractionWebhook.editMessage (C:\Kigo-2\node_modules\discord.js\src\structures\Webhook.js:338:15)
at async StringSelectMenuInteraction.editReply (C:\Kigo-2\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:158:17)
, this is my code:
async function createMenu(namev, vName, limit) {
const bt = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`${vName}_bt`)
.setLabel((!vName === true) ? "Activated" : "Deactivated")
.setStyle(Discord.ButtonStyle.Secondary)
);
const limit_menu = new Discord.ActionRowBuilder()
.addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId(`${namev}_limit_menu`)
.setPlaceholder(limit)
);
for (let i = 1; i <= 10; i++) {
limit_menu.addOptions(
new Discord.StringSelectMenuOptionBuilder()
.setLabel(i.toString())
.setValue(i.toString())
);
}
return { limit_menu, bt }
}
async function createMenu(namev, vName, limit) {
const bt = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`${vName}_bt`)
.setLabel((!vName === true) ? "Activated" : "Deactivated")
.setStyle(Discord.ButtonStyle.Secondary)
);
const limit_menu = new Discord.ActionRowBuilder()
.addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId(`${namev}_limit_menu`)
.setPlaceholder(limit)
);
for (let i = 1; i <= 10; i++) {
limit_menu.addOptions(
new Discord.StringSelectMenuOptionBuilder()
.setLabel(i.toString())
.setValue(i.toString())
);
}
return { limit_menu, bt }
}
6 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
JuanQ
JuanQOP2y ago
Node: v18.15.0 Discord.js: 14.11.0
Squid
Squid2y ago
How are you sending the rows?
JuanQ
JuanQOP2y ago
const { bt, limit_menu } = createMenu('cd', "role_d", '!Configura el limite del Eliminar Roles Masivamente!');
const { bt, limit_menu } = createMenu('cd', "role_d", '!Configura el limite del Eliminar Roles Masivamente!');
Squid
Squid2y ago
(also, ActionRowBuilder#addOptions() shouldn't work) createMenu() is an async function which means it returns a Promise and must be awaited
JuanQ
JuanQOP2y ago
oh okey that was it thank you
Want results from more Discord servers?
Add your server