Hey everyone. I'm trying to add a ButtonBuilder to a SectionBuilder, nested in a ContainerBuilder. But when trying to post the message, I get an error:
path/node_modules/@discordjs/builders/dist/index.mjs:486
throw new RangeError("Non-premium buttons must have a label and/or an emoji.");
^
RangeError: Non-premium buttons must have a label and/or an emoji.
at validateRequiredButtonParameters (path/node_modules/@discordjs/builders/dist/index.mjs:486:13)
at ButtonBuilder.toJSON (path/node_modules/@discordjs/builders/dist/index.mjs:654:5)
at SectionBuilder.toJSON (path/node_modules/@discordjs/builders/dist/index.mjs:2102:59)
at path/src/commands/polls/polls.js:271:34
at Array.forEach (<anonymous>)
at Object.action (path/src/commands/polls/polls.js:252:20)
Node.js v20.11.1
I tried to look at an error in my code but I cannot find one.
const container = new ContainerBuilder();
//create button
const buttonId = "polls_" + idx.toString();
const button = createButton(buttonId, field, ButtonStyle.Secondary, emote);
const fieldSection = new SectionBuilder().setButtonAccessory(button);
//line 271
console.log(fieldSection.toJSON());
container.addSectionComponents(fieldSection);
interaction.channel.send({flags: MessageFlags.IsComponentsV2, components: [container]});
//creatButton function:
export const createButton = (id, label, style, emoji) => {
const button = new ButtonBuilder().setCustomId(id).setStyle(style);
if (label) button.setLabel(label);
if (emoji) button.setEmoji(emoji);
return button;
};
When investigating the Builders, I have this weird accessory in the SectionBuilder:
SectionBuilder {
data: { type: 9 },
//components
accessory: ButtonBuilder {
data: {
type: 2,
data: {
type: 2,
emoji: undefined,
custom_id: 'polls_0',
style: 2,
label: 'Choice 1'
}
}
}
}