我怎样才能做到这一点,一旦用户点击消息中的一个按钮,该按钮就会被禁用,而其他按钮仍然可以点击?我正在使用 Discord.js v13.1.0,这是我迄今为止能够写的:
const { MessageActionRow, MessageButton } = require('discord.js');
let row = new MessageActionRow()
.addComponents(
but_1 = new MessageButton()
.setCustomId('id_1')
.setLabel('Button 1')
.setStyle('SECONDARY'),
but_2 = new MessageButton()
.setCustomId('id_2')
.setLabel('Button 2')
.setStyle('SECONDARY')
);
interaction.reply({ content: "Click a button", components: [row] })
我尝试创建消息组件收集器来检查单击的按钮的 id 并编辑按钮,但结果.addComponents()只是添加了另一个按钮而不是编辑它。这就是我所做的:
const filter = i => i.customId === 'id_1' && i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
collector.on('collect', async i => {
if (i.customId === 'id_1') {
row.addComponents(
but_1.setLabel('Click Registered!')
.setCustomId('id_1_clicked')
.setDisabled(true)
)
interaction.editReply({ content: "Click a button", components: [row] });
}
});