Home >Web Front-end >JS Tutorial >How to Fix Empty Message Content in Discord.js v14?
Discord.js: Retrieving Message Content in v14
In Discord.js v14, accessing message content through message.content may return empty values. This issue can be resolved by enabling the Message Content privileged gateway intent.
Enable Message Content Intent
Update Discord.js Code
Once the intent is enabled, update your Discord.js code as follows:
const { Client, GatewayIntentBits, Partials } = require('discord.js'); const bot = new Client({ intents: [ GatewayIntentBits.DirectMessages, GatewayIntentBits.Guilds, GatewayIntentBits.GuildBans, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], partials: [Partials.Channel], }); bot.on('messageCreate', (message) => { console.log(message.content); }); bot.login(process.env.token1);
Additional Notes
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.MESSAGE_CONTENT, ], });
The above is the detailed content of How to Fix Empty Message Content in Discord.js v14?. For more information, please follow other related articles on the PHP Chinese website!