Interactive Button Data

I want to make my Button label interactive but somehow it doesnt change when the variable changes:
const el = {power:"on"};

const bt = new Button({get label(){
return el.power
},...}) //Button extends ButtonBuilder
el.power = "off";
await interaction.reply({components: toComponents( bt) })
const el = {power:"on"};

const bt = new Button({get label(){
return el.power
},...}) //Button extends ButtonBuilder
el.power = "off";
await interaction.reply({components: toComponents( bt) })
I am sure its because the props are not directly linked to Buttonbuilder.data but just set once when initating the class right? Is there some way to fix that?
2 Replies
d.js toolkit
d.js toolkit•15mo 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!
Kumar
KumarOP•15mo ago
constructor(props: ButtonAndRunProps) {
super(props);
//with lodash merge
(this.data as any) = merge(props, this.data);
}
constructor(props: ButtonAndRunProps) {
super(props);
//with lodash merge
(this.data as any) = merge(props, this.data);
}
That seems to be a really ugly solution 🤔 maybe even bring some memory issues ?
Want results from more Discord servers?
Add your server