const defaultButtonGreen = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('defaultButtonGreen')
.setLabel('green')
.setStyle(ButtonStyle.Success),
),
defaultButtonRed = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('defaultButtonRed')
.setLabel('red')
.setStyle(ButtonStyle.Danger),
);
await interaction.reply({ content: "message", components: [defaultButtonGreen, defaultButtonRed] });
const message = await interaction.fetchReply();
const collector = message.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 60000
});
collector.on('collect', async i => {
if (i.customId === "defaultButtonGreen") {
defaultButtonGreen.components[0].setStyle(
defaultButtonGreen.components[0].data.style === 3 ? ButtonStyle.Danger : ButtonStyle.Success
);
await i.update({ components: [defaultButtonGreen, defaultButtonRed] })
} else if (i.customId === "defaultButtonRed") {
defaultButtonRed.components[0].setStyle(
defaultButtonRed.components[0].data.style === 4 ? ButtonStyle.Success : ButtonStyle.Danger
);
await i.update({ components: [defaultButtonGreen, defaultButtonRed] })
}
});
по нажатию на одну из двух кнопок, она будет менять цвет на противоположный (красный => зелёный, зелёный => красный).