0

So when i run my discord bot by using "npm run test" the error seems to be in the following line of code const button = require(../../components/${folder}/${file});... And here's the issue:

PS C:\Users\itstr\Documents\discord bot> npm run test

> discord-bot@1.0.0 test
> node .

Command: button has passed through the handler
Command: embed has passed through the handler
Command: modal has passed through the handler
Command: ping has passed through the handler
Started refreshing application (/) commands.
C:\Users\itstr\Documents\discord bot\node_modules\discord.js\src\client\Client.js:492
      throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
            ^

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
    at Client._validateOptions (C:\Users\itstr\Documents\discord bot\node_modules\discord.js\src\client\Client.js:492:13)
    at new Client (C:\Users\itstr\Documents\discord bot\node_modules\discord.js\src\client\Client.js:78:10)
    at Object.<anonymous> (C:\Users\itstr\Documents\discord bot\src\components\buttons\sub-yt.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1257:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
    at Module.load (node:internal/modules/cjs/loader:1115:32)
    at Module._load (node:internal/modules/cjs/loader:962:12)
    at Module.require (node:internal/modules/cjs/loader:1139:19)
    at require (node:internal/modules/helpers:121:18)
    at client.handleComponents (C:\Users\itstr\Documents\discord bot\src\functions\handler\handleComponents.js:16:28) {
  code: 'ClientMissingIntents'
}

Node.js v20.3.1

And here's the code:

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


module.exports = (client) => {
  client.handleComponents = async () => {
    const componentsFolder = readdirSync(`./src/components`);
    for (const folder of componentsFolder) {
      const componentsFiles = readdirSync(`./src/components/${folder}`).filter(file => file.endsWith('.js'));

      const { buttons, modals } = client;

      switch (folder) {
        case "buttons":
          for (const file of componentsFiles) {
            const button = require(`../../components/${folder}/${file}`);
            buttons.set(button.data.name, button);
          }
          break;

        case "modals":
          for (const file of componentsFiles) {
            const modal = require(`../../components/${folder}/${file}`);
            modals.set(modal.data.name, modal);
          }
          break;

        default:
          break;
      }
    }
  }
};



And by the way i tried doing:

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

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,             // Required for basic bot functionality
    Intents.FLAGS.GUILD_MESSAGES,     // Required for message events
    // Add more intents as per your bot's requirements
  ]
});

// Rest of your code...

client.login('YOUR_BOT_TOKEN');

And it didin't work, it only resulted with more errors.

I expect that i would learn of my past mistakes and that the community fixes it as soon as possible...

  • So what does `npm run test` do? Can you post the `scripts` property from your `package.json` file? – Zsolt Meszaros Jul 05 '23 at 12:10
  • Is this related to [this answer](https://stackoverflow.com/a/76608563/6126373)? Because that answer is absolutely wrong. – Zsolt Meszaros Jul 05 '23 at 12:15
  • And here's the package.json file `{ "name": "discord-bot", "version": "1.0.0", "main": "src/bot.js", "scripts": { "test": "node ." }, "keywords": [], "author": "", "license": "ISC", "description": "", "dependencies": { "@discordjs/rest": "^1.7.1", "chalk": "^4.1.2", "discord-api-types": "^0.37.46", "discord.js": "^14.11.0", "dotenv": "^16.3.1" } } ` – Tryder_56_PIXEL Jul 05 '23 at 12:19
  • 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 Jul 05 '23 at 12:21
  • Thanks. In v14, yuo should use `GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages`, not `Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES`. – Zsolt Meszaros Jul 05 '23 at 12:22
  • Yeah i know but i used GatewayIntentBits i just did a mistake while making the question – Tryder_56_PIXEL Jul 05 '23 at 12:23
  • can you update the code in your question? – Darshan B Jul 06 '23 at 06:29

0 Answers0