Home > Net >  TypeError: Cannot read properties of undefined (reading 'editReply')
TypeError: Cannot read properties of undefined (reading 'editReply')

Time:12-09

I'm making a bot with Discord.js and this is my code:

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)
    })
}

}

But I get an error in the terminal when I try to start the bot. This is the error I get:

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...

CodePudding user response:

I think you are seeing this because you're not getting the interaction back, from the prior call. If you use this (including the flag), it should help:

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

cheers!

CodePudding user response:

You need to set the fetchReply to true to return the message, but there really is no need... just use the original interaction

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

CodePudding user response:

The error is here

setTimeout(function()

there is another (

  • Related