使用后禁用按钮

编程入门 行业动态 更新时间:2024-10-07 10:16:35

使用后禁用<a href=https://www.elefans.com/category/jswz/34/1771318.html style=按钮"/>

使用后禁用按钮

我在我的

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

    }

我唯一不知道的是我如何禁用按钮。

有人可以帮忙吗?

回答如下:

您可以使用新的

MessageActionRow
创建一个新的
MessageButton
并使用
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] });

更多推荐

使用后禁用按钮

本文发布于:2024-05-30 06:37:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!