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

119
Views
Change button style if clicked in discord.js

I need help about changing the button style in Discord.JS. interaction.component.setStyle("DANGER") works, but for multi-buttons inside an Action Row doesn't work. I tried <row>.components, it shows an array of MessageButton. I can also <row>.components[0].setStyle("DANGER") but it can't do the clicked one. Can you please help? Thank you!

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

0

Using interaction.message.components[0] would return the first MessageActionRow.

Take a look at the image that I've linked below to see the numbers that I've been talking about.

In order to edit button 5, you would have to get the 2nd button of the 2nd row. This would be interaction.components[1].components[1]. You can then edit stuff like the style, label, etc. by running the usual .setLabel("Something") function.

Don't forget to reply to the interaction. In your case you would have to update the original interaction-message.

A possible way to insert this would be:

const { Client } = require("discord.js")
const client = new Client(/*Your intents*/)

//Your code to create the buttons, etc.

client.on("interactionCreate", interaction=>{
if(interaction.isButton()){
  if(interaction.customId=="your custom button id"){
    //Remember to start counting with 0. 0 in the code equals 1 in real life... 
    interaction.message.components[1].interaction[1].setStyle("DANGER")
    
    interaction.update({
      components: interaction.components
    })
  }
}
})
client.login("your token")

Buttons with the numbers I talked about.

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!