【问题标题】:Update discord-buttons on InteractionCreate更新 InteractionCreate 上的不和谐按钮
【发布时间】:2021-11-18 09:06:10
【问题描述】:

在 Discord MessageButtons 中,MessageActionRow

我有一个 MessageActionRow() 运行到消息嵌入中,在该消息中添加了按钮 addComponents,在 createInteraction 上单击“PauseButton”时,按钮替换为另一个名为“ResumeButton”的按钮,相同。

const PauseButton = new MessageButton()
.setCustomId('PauseButton')
.setLabel('Pause')
.setStyle('SUCCESS')
.setEmoji('⏸️');

const ResumeButton = new MessageButton()
.setCustomId('ResumeButton')
.setLabel('Resume')
.setStyle('SUCCESS')
.setEmoji('▶️');

//SkipButton, StopButton

const Buttons = new MessageActionRow().addComponents(PauseButton, SkipButton, StopButton);
const ResumeButtons = new MessageActionRow().addComponents(ResumeButton, SkipButton, StopButton);

const sendMessage = await QueueChannel.send({ embeds: [sendMessageEmbed], components: [Buttons] });

this.client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
// Pause
if (interaction.customId === "PauseButton") {
    player.pause(true);
    const int = await interaction.deferUpdate({
      fetchReply: true,
    });
    if (!int) return smt
    await int.edit({
      components: [ResumeButtons],
    });
    if(int.deleted) {
      interaction.channel.send()
    }
    }
// Resume
if (interaction.customId === "ResumeButton") {
    player.pause(false);
    const int = await interaction.deferUpdate({
      fetchReply: true,
    });
    if (!int) return smt
    await int.edit({
      components: [Buttons],
    });
    if(int.deleted) {
      interaction.channel.send()
    }
}

这将返回错误 DiscordAPIError: Unknown interaction ln line 23:13 await interaction.deferUpdate on await。

基本上,代码可以完成工作(功能齐全),除了: 在第一次运行,一切正常, 在第二次运行,当我点击任何按钮时,错误返回“未知交互” 原因是代码运行了两次,我知道当我在交互上添加console.log("PauseButton")时,日志返回到控制台PauseButton PauseButton而不是一次。

意味着 ineractionCreate 有 2 个侦听器吗?删除消息后是否需要删除任何交互?

我需要帮助,不胜感激!

【问题讨论】:

    标签: javascript node.js discord discord.js discord-buttons


    【解决方案1】:

    这个过程是重复的,因为我在那个项目中有一个interactionCreate.js。我感到很困惑,因为文件太多,代码没有问题,我很抱歉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-07
      • 2021-10-11
      • 1970-01-01
      • 2021-12-08
      • 2021-11-24
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      相关资源
      最近更新 更多