【问题标题】:TypeError: Cannot read properties of undefined (reading 'editReply')TypeError:无法读取未定义的属性(读取“editReply”)
【发布时间】:2022-01-13 20:07:24
【问题描述】:

我正在用 Discord.js 制作一个机器人,这是我的代码:

const { CommandInteraction, Interaction } = require("discord.js");

module.exports = {
name: "test",
description: "Tests the bot.",
ephemeral: "false",
permission: "SEND_MESSAGES",
/**
 * 
 * @param {CommandInteraction} interaction 
 */
execute(interaction) {
    interaction.reply({content: "Testing..."})
    .then(interaction => {
        setTimeout(function(){
            interaction.editReply("Test Successful ✔")
        }, 3000)
    })
}

}

但是当我尝试启动机器人时,我在终端中遇到了错误。这是我得到的错误:

C:\Users\Manuel\Desktop\Manuel\Programs\Programming\Visual Studio Code\Helix32 (Discord)\Commands\Developer\test.js:16
            interaction.editReply("Test Successful ✔")
                        ^

TypeError: Cannot read properties of undefined (reading 'editReply')
at Timeout._onTimeout (C:\Users\Manuel\Desktop\Manuel\Programs\Programming\Visual Studio Code\Helix32 (Discord)\Commands\Developer\test.js:16:29)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)

Node.js v17.2.0
[nodemon] app crashed - waiting for file changes before starting...

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    你需要将fetchReply设置为true才能返回消息,但是真的不需要……就用原来的交互方式

    interaction.reply({content: "Testing..."})
        .then(() => { //no "interaction" declaration
            setTimeout(function(){
                interaction.editReply("Test Successful ✔") //use original interaction object
            }, 3000)
        })
    

    【讨论】:

      【解决方案2】:

      我认为您看到这一点是因为您没有从之前的通话中恢复互动。如果您使用它(包括标志),它应该会有所帮助:

      interaction.reply({ content: 'Pong!', fetchReply: true })
      

      干杯!

      【讨论】:

        猜你喜欢
        • 2021-11-26
        • 2021-11-24
        • 2021-12-20
        • 2021-11-27
        • 2022-01-21
        • 2021-12-04
        • 2021-12-09
        • 2021-12-06
        • 2022-01-16
        相关资源
        最近更新 更多