Home >Web Front-end >JS Tutorial >Discord.js v14 Empty Message Content: How to Enable Message Content Intent?
Discord.js: Message Content Retrieval Issue
When attempting to utilize the messageCreate event in Discord.js version 14, you may encounter a situation where message.content returns an empty value. This problem arises due to the introduction of privileged intents in the new update.
To resolve this issue, follow these steps:
Discord Developer Portal:
Discord.js Intents Configuration:
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], });
Discord.js Event Listener:
client.on('messageCreate', (message) => {});
Discord API v10:
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.MESSAGE_CONTENT, ], });
By implementing these changes, you will allow your Discord.js bot to retrieve message content as expected.
The above is the detailed content of Discord.js v14 Empty Message Content: How to Enable Message Content Intent?. For more information, please follow other related articles on the PHP Chinese website!