Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Cannot read properties of undefined (reading 'execute)

On my discord bot, I am making a "nickname" command. My code on the nickname.js:

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
module.exports = {
    name: 'nick',
    description: 'This command with change a users nickname.',
    execute(message, args){
        const memberToEdit = message.mentions.members.first();
        const newNickname = message.content.replace(`${prefix}changenick`, '').split(' ').pop().trim();
        memberToEdit.setNickname(newNickname);
        }
}

The error I get whilst trying to run the command:

TypeError: Cannot read properties of undefined (reading 'execute')
    at Client.<anonymous> (C:\Users\Admin\Desktop\DiscordBot\main.js:79:36)
    at Client.emit (node:events:520:28)
    at MessageCreateAction.handle (C:\Users\Admin\Desktop\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Admin\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\Admin\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\Users\Admin\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\Admin\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\Admin\Desktop\DiscordBot\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:520:28)
    at Receiver.receiverOnMessage (C:\Users\Admin\Desktop\DiscordBot\node_modules\ws\lib\websocket.js:1137:20)

Node.js v17.4.0

My main.js file is the same as the rest of the commands which work fine...

  if(command === 'nick'){
    client.commands.get('nickname').execute(message, args)
  }

I can't seem to understand why this command specifically just wont work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As @PLASMA chicken said, the command you created is called nick, not nickname. So change nickname to nick where you call the execute function. For example, something like this:

if (command === 'nick') {
    client.commands.get('nick').execute(message, args);
}

Hoped this helped!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda