-1

I'm having an issue with importing the intents for my discord bot. (It was working and I believe I updated my discord.js version, tried downgrading and still couldnt get it to work so now im trying to get the new intents to work.)

This is how I have intents

const { Client, Intents } = require('discord.js');
const client = new Client({
  intents: [
    Intents.GUILDS,
    Intents.GUILD_MESSAGES,
    Intents.GUILD_MESSAGE_REACTIONS
  ]
});

I get this error

    Intents.GUILDS,
            ^

TypeError: Cannot read properties of undefined (reading 'GUILDS')

I have tried using different versions of discord.js and changing it from Intents to GatewayIntentBits like the discord.js docs says but then I get this error

      throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
      ^

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.

My original code was

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

and was working.

Does anyone know how to fix this or what version to downgrade for node and discord.js to get this working again.

Current Verions: Discord.js: 14.7.1 Node: 19.3.0

**EDIT I have updated my code to what discord.js refrences

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

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
    ],
});

and am now receiving this error. Intents are also enabled in the bot.

throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
      ^

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
    at Client._validateOptions (/home/runner/Discord-Bot/node_modules/discord.js/src/client/Client.js:489:13)
    at new Client (/home/runner/Discord-Bot/node_modules/discord.js/src/client/Client.js:78:10)
    at Object.<anonymous> (/home/runner/Discord-Bot/member-count.js:2:16)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/runner/Discord-Bot/index.js:22:21) {
  code: 'ClientMissingIntents'
}

Node.js v19.3.0
exit status 1
  • Does this answer your question? [Discord.js v13 code breaks when upgrading to v14](https://stackoverflow.com/questions/73028854/discord-js-v13-code-breaks-when-upgrading-to-v14) – Zsolt Meszaros Jan 08 '23 at 09:32

3 Answers3

0

GatewayIntentBits is the way to go as explained in the guide. Make sure to use PascalCase too.

The following error; TypeError [ClientMissingIntents]: Valid intents must be provided for the Client. is because you either:

  1. Have not enabled the intents necessary for the bot to perform its actions. Or 2. Have not enabled the correct privileged intents

If this still doesn't work please include the full error stack and your code associated with that error.

There is no need to downgrade as V14(.7.1) is a stable and functional version.

A list of intents can be found here
Tetie
  • 365
  • 1
  • 14
0

Answer

I noticed you are using the GatewayIntentBits correctly, but you need to make sure that you have enabled the corresponding intents through the Discord Developer Portal.

You can find the Priveleged Gateway Intents switches at https://discord.com/developers/applications/${APPLICATION_ID}/bot and enable them all if you wish.

I also noticed that you are using replit. As far as I know, Client._validateOptions checks if your bot can use the specified intents.

Example

It's always useful to add partials. I got this code from this repo.

const { Client, GatewayIntentBits, Partials, Collection, ActivityType } = require('discord.js')

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMessageReactions,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.MessageContent
  ],
  partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction]
})
Int Fract
  • 1
  • 2
-1

hmm, have u tried putting the intents like

const client = new Discord.Client({ intents:['GuildMessageTyping','GuildMembers','GuildEmojisAndStickers']});

this seemed to work for me.