[英]How can i edit button label 0 to 1 when pressed button on Discord.JS v14
if (!interaction.isButton()) return;
const pol = await polls.findOne({ message: interaction.message.id });
if (!pol) return;
await interaction.deferReply({
ephemeral: true
});
if (pol.voters.includes(interaction.user.id)) return interaction.editReply({
embeds: [{
color: 0xff0000,
title: "❌ Already Voted!"
}]
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
interaction.editReply({
embeds: [{
color: 0x008000,
title: "✅ Voted Successfully"
}]
});
},};
const m = interaction.message;
m.edit({
components: m.components?.map(row => {
row.components = row.components?.map(v => {
v.label = `${pol.votes[v.customId] || 0}`;
return v;
});
return row;
})
})
當按下 Discord.JS v14 上的按鈕時,如何將按鈕 label 0 編輯為 1
此代碼無效
我將此代碼 V13 轉換為 v14 但沒有用。 我該如何解決? 看指南,但我不明白
您可以使用同一個按鈕兩次,但在編輯時更改其 label。
查看您的代碼,您實際上並沒有發送任何帶有消息的組件。 試試下面的代碼。
const button = new ButtonBuilder().setLabel("0").setStyle(ButtonStyle.PRIMARY).setCustomId("test");
interaction.reply({
content: "Hello World",
components: [new ActionRowBuilder().addComponents(button)]
});
// inside the collector, to edit the label
interaction.editReply({
components: [new ActionRowBuilder().addComponents(button.setLabel("1"))]
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.