Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
multiple buttons in one ActionRow

I'm using the discord.js library and node.js to create a Discord bot that can send a DM to a user containing buttons.

I want to send a Discord message with multiple buttons, each with a unique customId and label. My current method is using an list of buttons. I use a for loop adding button objects to the list, and pass it in to the components of the .send method as a list.

x = 5
buttons = []

for (let i = 0; i < x; i++) {
    buttons.push(new MessageActionRow().addComponents(
        new MessageButton()
            .setCustomId(i.toString())
            .setLabel(messageSplit[i])
            .setStyle('PRIMARY')
        )
    )
}

msg.reply({ embeds: [embedRecipient], components: buttons })

This works, but each button is an new ActionRow of its own and thus resulting in the buttons being on different lines. What I mean: image of buttons each on a different line

How can I make it so the same features (like customId and Label) of the buttons retain but they are all on the same line? Making them all in the same one ActionRow should solve this I don't know the code to achieve that.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To put all the buttons in one single MessageActionRow, you could just declare the row outside the for loop and then inside it, you can just use .addComponents() to add a button to the MessageActionRow. An example is this:

x = 5
const buttons = new MessageActionRow()

for (let i = 0; i < x; i++) {
    buttons.addComponents(
        new MessageButton()
            .setCustomId(i.toString())
            .setLabel(messageSplit[i])
            .setStyle('PRIMARY')
        )
    )
}

msg.reply({ embeds: [embedRecipient], components: [buttons] })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!