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

520
Views
ReferenceError: message is not defined. Discord Bot error

I get this error when I try to run my code ReferenceError: message is not defined

at Client.<anonymous> (C:\Users\Diego M\Desktop\DiscordBot\index.js:14:1)
at Client.emit (node:events:390:28)
at MessageCreateAction.handle (C:\Users\Diego M\Desktop\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:33:18)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Diego M\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Diego M\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:350:31)
at WebSocketShard.onPacket (C:\Users\Diego M\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\Diego M\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\Diego M\Desktop\DiscordBot\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (C:\Users\Diego M\Desktop\DiscordBot\node_modules\ws\lib\websocket.js:1022:20)
const {
  Client,
  Intents
} = require('discord.js');
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
const prefix = '!';

client.on("ready", () => {
  console.log("Im Ready!");
});
client.on('message', messageCreate => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.lenght).split(/ +/);
  const command = args.shift().toLowerCase();

  if (command === 'ping') {
    message.channel.send('pong');
  }
});

client.login("Token");
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are getting the error because you are not providing the proper event and the parameter to the function. 'messageCreate' is an event which emits whenever a message is created and followed by a parameter. Have a look here

The code should look like this:

const { Client, Intents } = require('discord.js');
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const prefix = '!';

client.on('ready', () => {
  console.log('Im Ready!');
});
client.on('messageCreate', (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.lenght).split(/ +/);
  const command = args.shift().toLowerCase();

  if (command === 'ping') {
    message.channel.send('pong');
  }
});

client.login('Token');
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!