javascript 当运行此脚本的指定命令时,我得到此错误:TypeError:interaction.deferUpdate is not a function

sqyvllje  于 2024-01-05  发布在  Java
关注(0)|答案(1)|浏览(112)

以下是我的完整updates.js,当我在机器人中更改某些内容时,它会显示更新日志:
作为我项目的一部分

const { SlashCommandBuilder } = require("@discordjs/builders")
const { ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle } = require("discord.js")
async function handleUpdatesCommand(interaction) {
  interaction.deferUpdate()
  const requesterNickname = interaction.member.displayName
  console.log(`Updates ✅ - Requested by: ${requesterNickname}`)
  const updates = [
    {
      version: "v1.2 🔧\nlatest version ʙᴇᴛᴀ",
      changelog: "- Removed /giveaway for maintenance📌\n\n- Thanks for your patience ⸜(。˃ ᵕ ˂ )⸝♡ .",
      requestedBy: requesterNickname,
      timestamp: new Date("2023-12-27T16:00:00.000Z"),
    },
    {
      version: "v1.1 🔧\n ʙᴇᴛᴀ ",
      changelog: "• Only prefix is now `v`\n• Fixed RockPaperSicssors ✅\n• Bot no longer responds with false commands for user input\n\n𝗺𝗼𝗿𝗲 𝘀𝗼𝗼𝗻 .",
      requestedBy: requesterNickname,
      timestamp: new Date("2023-12-27T14:12:00.000Z"),
    },
    {
      version: "v1.0 🔧\n ʙᴇᴛᴀ",
      changelog: "• Removed old prefixes `!`, `&`, `/`\n• Added `v` prefix\n• Some cool emojis and fancy text for updates",
      requestedBy: requesterNickname,
      timestamp: new Date("2023-12-27T14:10:00.000Z"),
    },
    {
      version: "0.9.2\nʙᴇᴛᴀ",
      changelog: "- Added `vclear` to delete up to `100` messages",
      timestamp: new Date("2023-12-26T08:59:00.000Z"),
    }, // ... existing updates
  ]
  let currentPage = 0
  function createEmbed(currentUpdate, formattedDate, formattedTime) {
    // ... your existing createEmbed function
  }
  const formattedDate = "12/27/2023"
  const formattedTime = "2:00 PM"
  const row = new ActionRowBuilder().addComponents(
    new ButtonBuilder().setCustomId("previous").setLabel("⬅️ Previous").setStyle(ButtonStyle.Primary),
    new ButtonBuilder().setCustomId("next").setLabel("Next ➡️").setStyle(ButtonStyle.Primary),
  )
  const initialEmbed = createEmbed(updates[currentPage], formattedDate, formattedTime)
  const reply = await interaction.editReply({ embeds: [initialEmbed], components: [row] })
  const collector = reply.createMessageComponentCollector({ time: null })
  collector.on("collect", async (button) => {
    if (button.customId === "previous") {
      // Handle previous button click
      currentPage = Math.max(0, currentPage - 1)
    } else if (button.customId === "next") {
      // Handle next button click
      currentPage = Math.min(updates.length - 1, currentPage + 1)
    }
    // Update the embed with the new changelog
    const updatedEmbed = createEmbed(updates[currentPage], formattedDate, formattedTime)
    await reply.edit({ embeds: [updatedEmbed], components: [row] })

    // Check if the user has reached the limit
    if (currentPage === 0 || currentPage === updates.length - 1) {
      // Notify the user that they've reached the limit
      const direction = currentPage === 0 ? "latest" : "recent"
      await interaction.followUp({ content: `No more updates. You've reached the limit of the ${direction} changelogs.`, ephemeral: true })
    }
  })
}
module.exports = {
  data: new SlashCommandBuilder().setName("updates").setDescription("Get information about Violet updates🔧"),
  execute: handleUpdatesCommand,
}

字符串
我希望我创建的嵌入显示沿着与“上一页”和“下一页”按钮一起在更新日志之间导航。我还添加了一个交互,当用户偶然发现更新日志的限制时显示。
我还有一个“index.js”作为主脚本,用于处理每个命令和脚本的命令

uyhoqukh

uyhoqukh1#

我想你可能把await interaction.deferReply()拼错为interaction.deferUpdate()

相关问题