0

In a similar way to this post, the intent GatewayIntentBits.MessageContent doesn't seem to have a value.

The Privileged Gateway Intents is activated in the Developper portal
Image of my Privileged Gateway Intents

I added the GatewayIntentBits.MessageContent to my intents

const client = new Client({
    intents: [
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildPresences,
        GatewayIntentBits.GuildInvites,
        GatewayIntentBits.GuildEmojisAndStickers,
        GatewayIntentBits.GuildIntegrations,
        GatewayIntentBits.GuildWebhooks,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.MessageContent,
    ],
});

and i get this error on startup

    throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit);
    ^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
    at IntentsBitField.resolve (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/util/BitField.js:172:11)
    at /home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/util/BitField.js:167:54
    at Array.map (<anonymous>)
    at IntentsBitField.resolve (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/util/BitField.js:167:40)
    at new BitField (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/util/BitField.js:33:38)
    at new IntentsBitField (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/util/IntentsBitField.js:9:1)
    at Client._validateOptions (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/client/Client.js:494:25)
    at new Client (/home/pascalaubistrot/dev/Discord-Log/node_modules/discord.js/src/client/Client.js:78:10)    at Object.<anonymous> (/home/pascalaubistrot/dev/Discord-Log/index.js:8:16)
    at Module._compile (node:internal/modules/cjs/loader:1254:14) {
  code: 'BitFieldInvalid'
}

and VScode doesn't recognise the MessageContent flag Image of VScode intents and when I print the value of the intents it is undefined

GatewayIntentBits.GuildMembers : 2
GatewayIntentBits.MessageContent : undefined

And here is a console.log of the GateWayIntentsBits

{
  '1': 'Guilds',
  '2': 'GuildMembers',
  '4': 'GuildBans',
  '8': 'GuildEmojisAndStickers',
  '16': 'GuildIntegrations',
  '32': 'GuildWebhooks',
  '64': 'GuildInvites',
  '128': 'GuildVoiceStates',
  '256': 'GuildPresences',
  '512': 'GuildMessages',
  '1024': 'GuildMessageReactions',
  '2048': 'GuildMessageTyping',
  '4096': 'DirectMessages',
  '8192': 'DirectMessageReactions',
  '16384': 'DirectMessageTyping',
  '65536': 'GuildScheduledEvents',
  '1048576': 'AutoModerationConfiguration',
  '2097152': 'AutoModerationExecution',
  Guilds: 1,
  GuildMembers: 2,
  GuildModeration: 4,
  GuildBans: 4,
  GuildEmojisAndStickers: 8,
  GuildIntegrations: 16,
  GuildWebhooks: 32,
  GuildInvites: 64,
  GuildVoiceStates: 128,
  GuildPresences: 256,
  GuildMessages: 512,
  GuildMessageReactions: 1024,
  GuildMessageTyping: 2048,
  DirectMessages: 4096,
  DirectMessageReactions: 8192,
  DirectMessageTyping: 16384,
  GuildScheduledEvents: 65536,
  AutoModerationConfiguration: 1048576,
  AutoModerationExecution: 2097152
}

Version of discord.js: version: '14.11.0

Version of discord API: APIVersion: '10

Edit: I found out that i can pass the bitfields directly and the bot work fine and i can read the content of the message

const client = new Client({
    intents: 101917
});

I didn't find anyone else having this problem apart from this this post which was resolved but the solution didn't work for me.

AVNThomas
  • 1
  • 1
  • Can you post the value of `GatewayIntentBits`? (i.e add `console.log(GatewayIntentBits)` somewhere) – Zsolt Meszaros Jun 07 '23 at 06:03
  • Here you go I added it in my post @ZsoltMeszaros – AVNThomas Jun 07 '23 at 07:29
  • Thank you, could you also check your discord.js and API version? You can `import { APIVersion, version } from 'discord.js'` and then just `console.log({ APIVersion, version })` – Zsolt Meszaros Jun 07 '23 at 10:02
  • `{ APIVersion: '10', version: '14.11.0' }` I also made progress on my own, i passed the bitfield directly `intents: 101917` and I can access the message content. So i think the problem come from my installation of discord.js. But i just did `npm i discord.js` and changed version to try resolved the bug. – AVNThomas Jun 07 '23 at 11:37

1 Answers1

0

You are probably using discord.js v13. It uses Discord's API v9, which doesn't have the GatewayIntentBits.MessageContent intent.

You can verify that here discord-api-types v9 GatewayIntentBits reference

The MessageContent intent was introduced in Discord's API v10, so you should upgrade to discord.js v14 which uses the newer API v10 and that should fix the issue.

SlightlyEpic
  • 1
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '23 at 11:23
  • I'm on API v10, and on discord.js v14.11.0 – AVNThomas Jun 07 '23 at 11:46