Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

A discord.js bot receives messages but message.content is an empty string

Errormessage.content is an empty string

Short 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.

  • Applies to discord.js 14, Node.js 22, Discord Gateway API
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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);
    });
  2. 2Match what you see, then jump to its fix

    1. 1messageCreate 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. 2The 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. 3The 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

What does the error look like?

  • message.content is an empty string
  • messageCreate 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.js

2Fix

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.js

Confirmed by docs.discord.com

Did this fix it?

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 Intent

2Fix

Switch Message Content Intent on, save the page, and start the bot again.

node index.js

3Verify

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

Did this fix it?

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 Intent

2Fix

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 installed

Confirmed by discordjs.guide

Did this fix it?

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.