Discord bot unresponsive: Help needed

Hey everyone, I’m having trouble with my Discord bot. It’s up and running, but it’s not responding to messages. I’ve set it up using Node.js and Express, but something’s off.

Here’s a simplified version of my code:

const express = require('express');
const app = express();
const Discord = require('discord.js');

app.listen(8080, () => console.log('Server online'));

app.get('/', (req, res) => res.send('Bot is alive!'));

const bot = new Discord.Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'MESSAGE_CONTENT']});

bot.on('messageCreate', msg => {
  if (msg.content.toLowerCase() === 'hello') {
    msg.channel.send('Hi there!');
  }
});

bot.login(process.env.BOT_TOKEN);

The problem is, when I run this, it crashes with an error about an invalid bitfield flag: MESSAGE_CONTENT. I added this intent because someone suggested it, but now I’m stuck in a crash loop.

Any ideas on what I’m doing wrong or how to fix this? I’m pretty new to Discord bots, so any help would be awesome. Thanks!

hey, i had this issue too.

make sure u enabled message content intent in discord dev portal.

also, update your intents config to Discord.IntentsBitField.Flags.

that shud fix it.

lmk if you’re still havin probs!

I’ve encountered this issue before. The problem lies in specifying the intents. Instead of using strings, you need to use the IntentsBitField.Flags enum. Here’s how you can modify your code:

const { Client, IntentsBitField } = require('discord.js');

const bot = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.MessageContent
  ]
});

Also, ensure you’ve enabled the Message Content Intent in the Discord Developer Portal. It’s a privileged intent and must be manually activated. After making these changes, your bot should start responding to messages.

I ran into a similar problem with my Discord bot. The issue is with how you are configuring your intents. The MESSAGE_CONTENT intent is considered privileged and must be enabled in your bot settings on the Discord Developer Portal. To resolve this, open the Developer Portal, locate your application, go to the Bot section, and enable the MESSAGE CONTENT INTENT under Privileged Gateway Intents. Then update your code so that your intents include Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, and Discord.Intents.FLAGS.MESSAGE_CONTENT as shown below:

const bot = new Discord.Client({
  intents: [
    Discord.Intents.FLAGS.GUILDS,
    Discord.Intents.FLAGS.GUILD_MESSAGES,
    Discord.Intents.FLAGS.MESSAGE_CONTENT
  ]
});

This should fix the crash. Make sure you are using the latest version of discord.js.