A discord.js bot receives messages but message.content is an empty string
message.content is an empty stringShort answer
Discord only sends the text of other people's messages to bots that have the privileged Message Content intent. Without it, content, embeds, attachments and components arrive empty. Add GatewayIntentBits.MessageContent to the client and switch the same intent on in the Developer Portal Bot page. Both must be on.
Fix it fast
1Find out which cause you have
Log what the bot actually receives for one message typed by a person, and print the intents the client was created with. An empty string with a normal event means the intent is missing.
client.on('messageCreate', (message) => { console.log(JSON.stringify(message.content), message.author.bot); });2Match what you see, then jump to its fix
- 1
messageCreate fires for guild messages, but content is empty (the bot's own messages and mentions still show text)The client is created without the MessageContent intentFix - 2
The bot fails to log in with a disallowed-intents error, or the gateway closes with code 4014The intent is not enabled in the Developer PortalFix - 3
The bot is verified, or is nearing the point where verification is required, and the intent is not approvedThe bot is verified or close to the verification limit and the intent was not approvedFix
- 1
What does the error look like?
message.content is an empty stringmessageCreate fires but the command text is missing[DisallowedIntents]
Cause 1 of 3
The client is created without the MessageContent intent
1Check
Open the file that calls new Client and look at the intents array. Reading content, embeds, attachments and components needs three entries together: Guilds, GuildMessages and MessageContent.
grep -n -A6 "new Client" index.js2Fix
Add GatewayIntentBits.MessageContent next to the other two intents.
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});3Verify
Restart the bot and type a message in a channel it can see. The log line now shows your text.
node index.jsConfirmed by docs.discord.com
Cause 2 of 3
The intent is not enabled in the Developer Portal
1Check
A privileged intent has to be enabled in the Developer Portal before the app may send it. If the code asks for it and the portal toggle is off, Discord closes the connection with 4014.
# Developer Portal: your application > Bot > Privileged Gateway Intents > Message Content Intent2Fix
Switch Message Content Intent on, save the page, and start the bot again.
node index.js3Verify
The bot logs in without a disallowed-intents error and messages carry their text.
node -e "console.log('start the bot and send one message')"Confirmed by docs.discord.com
Cause 3 of 3
The bot is verified or close to the verification limit and the intent was not approved
1Check
Apps that qualify for verification must also be approved for each privileged intent. The discord.js guide says unverified bots in fewer than 100 guilds can enable it directly; verified bots, or bots about to need verification, must apply.
# Developer Portal: your application > Bot, read the note under Message Content Intent2Fix
Apply for the intent through the verification process, or stop depending on message text and use slash commands or mentions, which do not need it.
// Slash command handler: no Message Content intent needed
client.on('interactionCreate', (interaction) => {
if (interaction.isChatInputCommand() && interaction.commandName === 'ping') {
interaction.reply('pong');
}
});3Verify
The command answers while the client only has the Guilds intent.
# run /ping in a server where the bot is installedConfirmed by discordjs.guide
How do I stop it coming back?
- Decide early whether the bot truly needs message text. Slash commands and mentions work without the privileged intent.
- Keep the intents array in one place and review it whenever a command stops seeing messages.
- Check the privileged-intent toggles in the portal after moving a bot to a new application or token.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix