NodeJS 使用后禁用按钮|Discord.js v14

gudnpqoy  于 2023-04-29  发布在  Node.js
关注(0)|答案(1)|浏览(173)

我在我的index.js中写了这个,当一个按钮被按下时回复,然后禁用它。

client.on("interactionCreate",  async (interaction) => {
  if (interaction.isButton()) {
    if (interaction.customId === "yes") {
      const owner_role = await db.get(`Owner-${interaction.guild.id}`);

      if (!owner_role) {
        return interaction.reply({ content: `:no: The server's owner haven't set up the bot yet. Please contact them.`, ephemeral: true })
      };

      if (!interaction.member.roles.cache.has(owner_role)) {
        return interaction.reply({ content: ":no: You don't have permission to use this command.", ephemeral: true })
      };

      interaction.reply(`This suggestion has been approved by ${interaction.user}.`)

      // Disable the button

    }

我唯一不知道的是,我如何禁用按钮。
有人能帮帮忙吗?

j13ufse2

j13ufse21#

您可以使用新的MessageButton创建新的MessageActionRow,并使用setDisabled(true)禁用它

await interaction.reply(`This suggestion has been approved by ${interaction.user}.`);

  const row = new MessageActionRow()
    .addComponents(
      new MessageButton()
        .setCustomId('customId')
        .setLabel('some label')
        .setDisabled(true)
    );

  await interaction.editReply({ components: [row] });

相关问题