How to update style of a button?

Hi, I'm trying to upgrade from v13 to v14. Given a message object, how can I update the style of a specific button?
13 Replies
d.js toolkit
d.js toolkit12mo 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!
Eden
EdenOP12mo ago
Also I'm using typescript
Eden
EdenOP12mo ago
I know how to style a button, I'm just not sure how to edit a specific button inside a message right now the problem is that the components of the message I've fetched is the type of ActionRow<MessageActionRowComponent>[], but when I use a ButtonBuilder to create a new button, I'm just not sure how to "compile" it into the type of MessageActionRowComponent so that typescript is happy
Svitkona
Svitkona12mo ago
well, you need to narrow it first to ButtonComponent then you should be able to do ButtonBuilder.from(component)
Eden
EdenOP12mo ago
right now I'm trying this:
let rows = msg.components
const newRow = new ActionRowBuilder(rows[row]);
const button = new ButtonBuilder()
newRow.components[column] = button
rows[row] = newRow
await msg.edit({components: rows})
let rows = msg.components
const newRow = new ActionRowBuilder(rows[row]);
const button = new ButtonBuilder()
newRow.components[column] = button
rows[row] = newRow
await msg.edit({components: rows})
but the line
rows[row] = newRow
rows[row] = newRow
gives
Type 'ActionRowBuilder<AnyComponentBuilder>' is missing the following properties from type 'ActionRow<MessageActionRowComponent>': type, equalsts(2739)
Type 'ActionRowBuilder<AnyComponentBuilder>' is missing the following properties from type 'ActionRow<MessageActionRowComponent>': type, equalsts(2739)
Harnes
Harnes12mo ago
Create a new row and use static ButtonBuilder#from method Then edit his property And edit message with a new row
d.js docs
d.js docs12mo ago
method (static) ButtonBuilder.from() Creates a new button builder from JSON data
Eden
EdenOP12mo ago
I have all the button styles stored; can I just make a new button using ButtonBuiler() or do I still need to use ButtonBuilder.from()?
Harnes
Harnes12mo ago
If you want to label and other values to be the same you should use ButtonBuilder#from This basically creates a new builder from button json object that you can access in message components property Also you are missing this
d.js docs
d.js docs12mo ago
In TypeScript the ActionRowBuilder class has a generic type parameter that specifies the type of component the action row holds:
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button)
const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu)
const row = new ActionRowBuilder<TextInputBuilder>().addComponents(textInput)
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button)
const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu)
const row = new ActionRowBuilder<TextInputBuilder>().addComponents(textInput)
Eden
EdenOP12mo ago
hmm okay I will do some experimentation ty
Want results from more Discord servers?
Add your server