Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

message.content doesn't have any value in Discord.js

With discord v14, I was trying to use the messageCreate event, however, after a user types a message in discord, message.content doesn't have any data as shown below:

Message {
  channelId: '998889338475655188',
  guildId: '948995127148425246',
  id: '998925735668498433',
  createdTimestamp: 1658232854526,
  type: 0,
  system: false,
  content: '',
  author: User 

I have tried searching around and can't find any solution to the issue, the code I am using relating to discord is:

import { Client, GatewayIntentBits, Partials } from "discord.js";

const bot = new Client({
  'intents': [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages
  ],
  'partials': [Partials.Channel]
});

bot.on('messageCreate', async (message) => {
  console.log(message);
});

bot.login(process.env.token1)

Does anyone have any idea what is wrong or what needs changing from the new update?

like image 530
user19530601 Avatar asked Sep 14 '25 08:09

user19530601


1 Answers

Make sure you enable the message content intent on your developer portal and add the GatewayIntentBits.MessageContent enum to your intents array.

Applications ↦ Settings ↦ Bot ↦ Privileged Gateway Intents

enter image description here

You'll also need to add the MessageContent intent:

const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
  partials: [Partials.Channel],
});

And make sure to use the messageCreate event instead of message:

client.on('messageCreate', (message) => {});

If you're using discord.js v13, you'll need to enable the message content intent on your developer portal and if your bot uses the Discord API v10, you will need to add the MESSAGE_CONTENT flag to your intents:

const { Client, Intents } = require('discord.js');
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.MESSAGE_CONTENT,
  ],
});
like image 182
Zsolt Meszaros Avatar answered Sep 15 '25 22:09

Zsolt Meszaros