new Responder({
customId: "premium/assinar/plus",
type: ResponderType.Button,
cache: "cached",
async run(interaction) {
const currentMonth = 1; // I'm still thinking about a code that makes it possible to count the number of times the button has been clicked
const monthVariable = currentMonth > 1 ? "meses" : "mês";
const currentPrice = 9.9 * currentMonth;
const button = ButtonBuilder.from(interaction.component).setLabel(
`${currentMonth} ${monthVariable} (R$${currentPrice})`,
);
const subscribeRowIndex = interaction.message.components.findIndex((row) =>
row.components.some(
(component) => component.customId === "premium/assinar/months",
),
);
if (subscribeRowIndex !== -1) {
const subscribeRow = interaction.message.components[subscribeRowIndex];
const updatedComponents = subscribeRow.components.map((component) => {
if (component.customId === "premium/assinar/months") {
return button;
}
return component;
});
console.log(updatedComponents);
// interaction.message.components[subscribeRowIndex] = { ...subscribeRow, components: updatedComponents };
}
// await interaction.update({ components: [subscribeRow] });
},
});
new Responder({
customId: "premium/assinar/plus",
type: ResponderType.Button,
cache: "cached",
async run(interaction) {
const currentMonth = 1; // I'm still thinking about a code that makes it possible to count the number of times the button has been clicked
const monthVariable = currentMonth > 1 ? "meses" : "mês";
const currentPrice = 9.9 * currentMonth;
const button = ButtonBuilder.from(interaction.component).setLabel(
`${currentMonth} ${monthVariable} (R$${currentPrice})`,
);
const subscribeRowIndex = interaction.message.components.findIndex((row) =>
row.components.some(
(component) => component.customId === "premium/assinar/months",
),
);
if (subscribeRowIndex !== -1) {
const subscribeRow = interaction.message.components[subscribeRowIndex];
const updatedComponents = subscribeRow.components.map((component) => {
if (component.customId === "premium/assinar/months") {
return button;
}
return component;
});
console.log(updatedComponents);
// interaction.message.components[subscribeRowIndex] = { ...subscribeRow, components: updatedComponents };
}
// await interaction.update({ components: [subscribeRow] });
},
});