Home >Web Front-end >JS Tutorial >Why is `message.content` Empty in My Discord.js v14 Bot?
When using Discord.js version 14, you may encounter an issue where the message.content property is empty when a user sends a message. This occurs because the Message Content intent is not enabled or the correct Gateway Intent Bit is not included.
Solution:
Enable the Message Content Intent:
Add the GatewayIntentBits.MessageContent Enum:
In your Discord.js code, revise the intents array like this:
intents: [ GatewayIntentBits.DirectMessages, GatewayIntentBits.Guilds, GatewayIntentBits.GuildBans, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ],
Use the 'messageCreate' Event:
Make sure you are using the messageCreate event, not the message event, for handling messages:
bot.on('messageCreate', async (message) => { // Your code here });
By enabling the Message Content intent and adding the proper Gateway Intent Bit, you will restore the message.content property with the actual message text.
The above is the detailed content of Why is `message.content` Empty in My Discord.js v14 Bot?. For more information, please follow other related articles on the PHP Chinese website!