#Can't execute commands with options

19 messages · Page 1 of 1 (latest)

dim sparrow
#

Discord.js Version: 14.3.0
Node.js Version: 17.0.1

I've been following the guide and went through the commands with options, but I can't execute /echo. I always get the error "TypeError: command.execute is not a function"

Here is my code for the interaction handler:

async execute(interaction) {
  if (!interaction.isChatInputCommand()) return;
    // fetch the command, and see if it is valid
    const command = interaction.client.commands.get(interaction.commandName);
    if (!command) return;

    // execute the command, catch and log err
    console.log(`'${interaction.user.tag}' in '#${interaction.channel.name}' triggered '/${interaction.commandName}'`);
    try {
      await command.execute(interaction);
    }
    catch (error) {
      console.log(`\x1b[1m\x1b[31m └── ${error}\x1b[0m`);
      console.trace();
      await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
},
whole solsticeBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

dim sparrow
#

Stack Trace:

at Object.execute (C:\Users\pitch\Desktop\Undefined-bot\events\interactionCreate.js:18:12)
    at Client.<anonymous> (C:\Users\pitch\Desktop\Undefined-bot\index.js:33:44)    at Client.emit (node:events:390:28)
    at InteractionCreateAction.handle (C:\Users\pitch\Desktop\Undefined-bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
    at Object.module.exports [as INTERACTION_CREATE] (C:\Users\pitch\Desktop\Undefined-bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_C    at WebSocketManager.handlePacket (C:\Users\pitch\Desktop\Undefined-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
    at WebSocketShard.onPacket (C:\Users\pitch\Desktop\Undefined-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
    at WebSocketShard.onMessage (C:\Users\pitch\Desktop\Undefined-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
    at WebSocket.onMessage (C:\Users\pitch\Desktop\Undefined-bot\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:390:28)
#

I've updated to v14.4.0 and it is still happening

celest nebula
#

log command before calling command.execute()

dim sparrow
#

command just returns [object Object]

#

Other non option commands work, it's just option commands

celest nebula
#

use console.log()

#

or something else that uses util.format or similar under the hood

celest nebula
#

not sure what an "option command" is

dim sparrow
#

interaction return /echo input:test

celest nebula
#

a command with options

dim sparrow
#

yes

celest nebula
#

just use console.log(command) before command.execute()

dim sparrow
#

Oh, didn't know that was going to do something different

{
  data: {
    name: 'echo',
    description: 'Replies with your input',
    options: [ [Object] ],
    default_permission: undefined,
    default_member_permissions: undefined,
    dm_permission: undefined
  }
}
celest nebula
#

doesnt seem like that command has an execute function

dim sparrow
#

....... i looked over the echo.js file multiple times, and never did i notice that i forgot async execute(interaction) {};