0

I started a new project to make a bot for discord, but I always use the same setup every time I create a new discord bot project and update the setup if there is an update in discord.js. In here, I was trying to send a message when the user('s) sends a message.

import { Client, IntentsBitField } from "discord.js"
const client = new Client({ 
  intents: [
    IntentsBitField.Flags.GuildMessages, 
    IntentsBitField.Flags.Guilds
  ] 
});

import dotenv from "dotenv"
dotenv.config();

client.on("ready", () => {
  console.log("astoon bot is READY!");
});

// Detecting if there is a message created.
client.on("messageCreate", (message) => {
  if (message.content === "ping") {
    message.reply("Pong!");
  };
});

client.login(process.env.TOKEN);
Demon
  • 1

1 Answers1

1

Change your code intent to:

import { Client, IntentsBitField } from "discord.js"
const client = new Client({ 
  intents: [
    IntentsBitField.Flags.GuildMessages, 
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.MessageContent // Add this line.
  ] 
});

import dotenv from "dotenv"
dotenv.config();

client.on("ready", () => {
  console.log("astoon bot is READY!");
});

// Detecting if there is a message created.
client.on("messageCreate", (message) => {
  if (message.content === "ping") {
    message.reply("Pong!");
  };
});

client.login(process.env.TOKEN);

If you don't do this, you'll get an empty string on message.content. And remember this: This

Chang Alex
  • 505
  • 3
  • 11