Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda