Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!