-1

I'm using nodejs. My packages are express and discord.js v14.

My code: enter image description here

if I add "MESSAGE_CONTENT" to

const client = new Discord.Client({intents: \["GUILDS", "GUILD_MESSAGES"\]});

I get this error code:

RangeError \[BITFIELD_INVALID\]: Invalid bitfield flag or number: MESSAGE_CONTENT.
at Function.resolve (/home/runner/my-bot-project-2/node_modules/discord.js/src/util/BitField.js:152:11)
at /home/runner/my-bot-project-2/node_modules/discord.js/src/util/BitField.js:147:54
at Array.map (\<anonymous\>)
at Function.resolve (/home/runner/my-bot-project-2/node_modules/discord.js/src/util/BitField.js:147:40)
at Client.\_validateOptions (/home/runner/my-bot-project-2/node_modules/discord.js/src/client/Client.js:550:33)
at new Client (/home/runner/my-bot-project-2/node_modules/discord.js/src/client/Client.js:76:10)
at Object.\<anonymous\> (/home/runner/my-bot-project-2/index.js:5:16)
at Module.\_compile (node:internal/modules/cjs/loader:1198:14)

I tried searching in discord.js guide v14 but didn't find anything.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • 1
    Does this answer your question? [Cannot read properties of undefined (reading 'guilds') on discord.js v14](https://stackoverflow.com/questions/76676659/cannot-read-properties-of-undefined-reading-guilds-on-discord-js-v14) – waki285 Aug 22 '23 at 04:31
  • Does this answer your question? [message.content doesn't have any value in Discord.js](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js) – Zsolt Meszaros Aug 22 '23 at 21:10

1 Answers1

-3

You're using an invalid intent "MESSAGE_CONTENT" in Discord.js v14. Here's how to fix it:

  1. Remove "MESSAGE_CONTENT" from the intents list.
  2. Use only valid intents like:
    • "GUILDS"
    • "GUILD_MESSAGES"
  3. Update your code to:
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]});
  1. Ensure your bot has the right permissions in Discord to read messages.
MaikeruDev
  • 1,075
  • 1
  • 19
  • Intents are no longer strings, but rather `GatewayIntentBits` values – Elitezen Aug 22 '23 at 12:27
  • Right, then it would look like this: `const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] }); ` – MaikeruDev Aug 22 '23 at 12:30
  • Not for v14. The correct way in v14 would be `intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ... ]` – Elitezen Aug 23 '23 at 22:33