Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda