Can you parse and return components?

I had a button action row working just fine
...
const leBtn = new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setEmoji(`${config.leRoleEmoji}`)
.setCustomId("le_btn");
const row = new ActionRowBuilder()
.addComponents(tuBtn)
.addComponents(suBtn)
.addComponents(leBtn)
...
const leBtn = new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setEmoji(`${config.leRoleEmoji}`)
.setCustomId("le_btn");
const row = new ActionRowBuilder()
.addComponents(tuBtn)
.addComponents(suBtn)
.addComponents(leBtn)
But I wanted to centralise some code so I tried to make a function to create the button action rows and return them for later use
const embed = await buildEmbedOptions(interaction, selectedOption);
const row = await buildEmbedButtons(interaction, selectedOption);
await interaction.reply({
embeds: [embed],
components: [row],
});
const embed = await buildEmbedOptions(interaction, selectedOption);
const row = await buildEmbedButtons(interaction, selectedOption);
await interaction.reply({
embeds: [embed],
components: [row],
});
I can log the return of the action row fine:
buttons [
{ style: 'Secondary', label: '⚽', customId: 'tu_btn' },
{ style: 'Secondary', label: '📁', customId: 'su_btn' },
{ style: 'Secondary', label: '👍', customId: 'le_btn' },
]
final row [
ActionRowBuilder {
data: { type: 1 },
components: [
[ButtonBuilder],
[ButtonBuilder],
[ButtonBuilder],
]
}
]
buttons [
{ style: 'Secondary', label: '⚽', customId: 'tu_btn' },
{ style: 'Secondary', label: '📁', customId: 'su_btn' },
{ style: 'Secondary', label: '👍', customId: 'le_btn' },
]
final row [
ActionRowBuilder {
data: { type: 1 },
components: [
[ButtonBuilder],
[ButtonBuilder],
[ButtonBuilder],
]
}
]
But I get this error when trying to send them
DiscordAPIError[50035]: Invalid Form Body
data.components[0].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 5 in length.
...
requestBody: {
files: [],
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Get Notified!',
description: 'txt here',
color: 13408563,
footer: [Object]
}
],
components: [ { '0': [Object], type: 1, components: [] } ],
DiscordAPIError[50035]: Invalid Form Body
data.components[0].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 5 in length.
...
requestBody: {
files: [],
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Get Notified!',
description: 'txt here',
color: 13408563,
footer: [Object]
}
],
components: [ { '0': [Object], type: 1, components: [] } ],
5 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Lord_TCG#9068
Lord_TCG#9068OP10mo ago
Normally I do stay to one channel, I run a support server myself. Wasn't sure if that was more of a chat channel so switched over to a forum Honestly... I added in the logs to send your way and it started working. Idk why, idk what I changed... I've been going in circles for hours troubleshooting line by line... 🤷‍♂️ You must be my good luck charm idk
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Lord_TCG#9068
Lord_TCG#9068OP10mo ago
I added logs at every stage, switched the logic in the for each loop, lowered my array to 1 object... I'd tried everything I could think of. But I appreciate your time
Want results from more Discord servers?
Add your server