Buttons!

Having an error with some buttons. Developing in replit, Invalid form body error.
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
20 Replies
d.js toolkit
d.js toolkit15mo 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! - Marked as resolved by OP
Epsilon
EpsilonOP15mo ago
node:events:491
throw er; // Unhandled 'error' event
^

DiscordAPIError[50035]: Invalid Form Body
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Heres your cheeseburger!',
description: '🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞',
color: 90399
}
],
components: [
{
type: 2,
emoji: undefined,
label: 'Assemble cheeseburger!',
style: 1
}
],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
data: { components: { '0': { custom_id: [Object] } } }
}
},
code: 50035,
status: 400,
method: 'POST',
url: ''
}

Node.js v18.16.1
exit status 1
node:events:491
throw er; // Unhandled 'error' event
^

DiscordAPIError[50035]: Invalid Form Body
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Heres your cheeseburger!',
description: '🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞',
color: 90399
}
],
components: [
{
type: 2,
emoji: undefined,
label: 'Assemble cheeseburger!',
style: 1
}
],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
data: { components: { '0': { custom_id: [Object] } } }
}
},
code: 50035,
status: 400,
method: 'POST',
url: ''
}

Node.js v18.16.1
exit status 1
Epsilon
EpsilonOP15mo ago
Needed to chop some bits off for message length.
Danial
Danial15mo ago
Your button is missing the custom id
Epsilon
EpsilonOP15mo ago
Type error when I add it in.
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.customID("chzburgID")

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.customID("chzburgID")

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
node bot.js
/home/runner/silos-bot-of-wonders/bot.js:15
.customID("chzburgID")
^

TypeError: (intermediate value).setLabel(...).setStyle(...).customID is not a function
at Object.<anonymous> (/home/runner/silos-bot-of-wonders/bot.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.16.1
exit status 1
node bot.js
/home/runner/silos-bot-of-wonders/bot.js:15
.customID("chzburgID")
^

TypeError: (intermediate value).setLabel(...).setStyle(...).customID is not a function
at Object.<anonymous> (/home/runner/silos-bot-of-wonders/bot.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.16.1
exit status 1
Danial
Danial15mo ago
It's .setCustomId()
Epsilon
EpsilonOP15mo ago
node bot.js
/home/runner/silos-bot-of-wonders/bot.js:15
.setCustomID("chzburgID")
^

TypeError: (intermediate value).setLabel(...).setStyle(...).setCustomID is not a function
at Object.<anonymous> (/home/runner/silos-bot-of-wonders/bot.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.16.1
exit status 1
node bot.js
/home/runner/silos-bot-of-wonders/bot.js:15
.setCustomID("chzburgID")
^

TypeError: (intermediate value).setLabel(...).setStyle(...).setCustomID is not a function
at Object.<anonymous> (/home/runner/silos-bot-of-wonders/bot.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.16.1
exit status 1
Danial
Danial15mo ago
Show your code
Epsilon
EpsilonOP15mo ago
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.setCustomID("chzburgID")

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
const { Client, GatewayIntentBits, EmbedBuilder, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const TOKEN = process.env['TOKEN']

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);

client.user.setPresence({ activities: [{ name: 'over a ton of cheeseburgers.', type: ActivityType.Watching }], status: 'online' })

});
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.setCustomID("chzburgID")

const chzburgEmbed = new EmbedBuilder()
.setTitle("Heres your cheeseburger!")
.setDescription("🍞\n 🥬\n 🧀\n 🥓\n 🥩\n 🍞")
.setColor(0x01611F)


client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'cheeseburger') {
await interaction.reply ({embeds: [chzburgEmbed], components:[chzburgButton]})

}
});

client.login(TOKEN);
Danial
Danial15mo ago
.setCustomId()
Epsilon
EpsilonOP15mo ago
Yikes.
Epsilon
EpsilonOP15mo ago
d.js docs
d.js docs15mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
Danial
Danial15mo ago
Can't see preview on the phone, please use this
Epsilon
EpsilonOP15mo ago
Pastebin
 node bot.jsLogged in as silo's bot of wonders#4253!node:events:49...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
treble/luna
treble/luna15mo ago
Your components need to be wrapped in an actionrow
d.js docs
d.js docs15mo ago
class ActionRowBuilder (extends ComponentBuilder) Represents an action row component
Epsilon
EpsilonOP15mo ago
const actionRow = new ActionRowBuilder({
components: [
{
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.setCustomId("chzburgID")
},
],
});
const actionRow = new ActionRowBuilder({
components: [
{
const chzburgButton = new ButtonBuilder()
.setLabel("Assemble cheeseburger!")
.setStyle(ButtonStyle.Primary)
.setCustomId("chzburgID")
},
],
});
treble/luna
treble/luna15mo ago
if you're just gonna use raw json theres no need to wrap it in a builder and thats invalid js
d.js docs
d.js docs15mo ago
guide Message Components: Buttons read more
Want results from more Discord servers?
Add your server