I am new to programming in discord.js. I have been trying to implement a discord bot that is able to have a chatgpt chatbot and a music bot. The reason why I have the FLAGS intent is for my music bot feature. Non-flags intent are for ChatGPT. It seems that after I added them both, the problem occured. TypeError [ClientMissingIntents]: Valid intents must be provided for the Client. at Client._validateOptions (C:\Users\x\Desktop\bot\node_modules\discord.js\src\client\Client.js:489:13) at new Client (C:\Users\x\Desktop\bot\node_modules\discord.js\src\client\Client.js:78:10) at Object. (C:\Users\x\Desktop\bot\main.js:3:16) at Module._compile (node:internal/modules/cjs/loader:1246:14) at Module.load (node:internal/modules/cjs/loader:1103:32) at Module._load (node:internal/modules/cjs/loader:942:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) at node:internal/main/run_main_module:23:47 { code: 'ClientMissingIntents' }

Here's my code. (index.js file)


const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { Client, GatewayIntentBits, Collection, Events} = require("discord.js");
const { Player } = require("discord-player");
const { token } = require('./config.json');

const fs = require("node:fs");
const path = require("node:path");

import { ChatGPT } from "discord-chat-gpt";

const client = new Client({
    intents: [
        GatewayIntentBits.FLAGS.GUILDS,
        GatewayIntentBits.FLAGS.GUILD_MESSAGES,
        GatewayIntentBits.FLAGS.GUILD_VOICE_STATES,
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ],
    allowedMentions: {
        repliedUser: false, //to not let it ping me for 1million times 
    },
});

const gptClient = new ChatGPT({
    apiKey: `insertapikeyhere`, //
    orgKey: `insertorgkeyhere`, // 
  });

// Checking if bot is online (logger)
client.on("ready", () => {
    console.log('> ${client.user.username}is online!');
});

// Chat Bot System
client.on('messageCreate', async (message) => {
    if(!message.guild || message.author.bot) return;
    let ChannelID = "insertchannelidhere";
    let channel = message.guild.channels.cache.get(ChannelID);
    if (!channel) return;
    if (message.channel.id === channel.id) {
        let msg = await message.reply({
            content: `Loading... Please Wait.`,
        });
        let reply = await gptClient.chat(message.content,message.author.username);
        msg.edit({
            content: `${reply}`,
        });
    }
});

import {Client, GatewayIntentBits} from "discord.js"

// Load all the commands
const commands = [];
client.commands = new Collection();

const commandsPath = path.join(__dirname,"conmmands");
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith("js."));

for (const file of commandFiles)
{
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);

    client.commands.set(command.data.name, command);
    commands.push(command);
}

client.player = new Player(client, {
    ytdlOptions: {
        quality: "highestaudio",
        highWaterMark: 1 << 25 
    }
});


client.on("ready", async () => {
    const guild_ids = client.guilds.cache.map(guild => guild.id);

    const rest = new REST({ version: "9" }).setToken(token);
    for (const guildId of guild_ids) {
        rest.put(Routes.applicationGuildCommands(client.application.id, guildId), {
            body: commands,
        })
            .then(() => console.log(`Added commands to ${guildId}`))
            .catch(console.error);
    }

    // Set the application commands
    await client.application.commands.set(commands);
    console.log("Commands registered!");
});

client.on("interactionCreate", async interaction => {
    if(!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);
    if(!command) return;

    try
    {
        await command.execute({client, interaction});
    }
    catch(err)
    {
        console.error(err);
        await interaction.reply("Sorry, an error occuured while executing that command. :C")
    }
});

client.application.commands.set();
client.login(token);

I have been trying to find this solution for 2 hours, sadly nothing has come by. Hope you

I tried to ;

  1. Changed intent to gatewayintentbits
  2. Changed INTERACTION_CREATE to interactionCreate
  3. Updated node.js to latest (version 19)
  4. Updated discord.js to latest (version 14)
  5. Asked chatgpt, said that it had to do with intent. Still a dead end hahaha
  6. Checked other QnA's didn't helped

What did I do?

  1. In terminal, I inputted node . then it shows,code: 'ClientMissingIntents'

Here's the full package file.

{
  "naexme": "bot",
  "version": "1.0.0",
  "description": "discordbot",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "helyz",
  "license": "ISC",
  "dependencies": {
    "@discordjs/opus": "^0.9.0",
    "@discordjs/voice": "^0.14.0",
    "discord-chat-gpt": "^1.0.2",
    "discord-player": "^5.4.0",
    "discord.js": "^14.7.1",
    "dotenv": "^16.0.3",
    "ffmpeg-static": "^5.1.0"
  }
}

1

There are 1 best solutions below

2
On

In the change from v13 to v14 the way that intents are selected changed, you've used both methods.

GatewayIntentBits.FLAGS.GUILDS, is the old way of doing it.

You are on the right track as you also have the new way of doing it, GatewayIntentBits.Guilds is the correct syntax.

All you need to do is remove the first three intents, as they are using an outdated method.

If you are upgrading your project from v13 to v14, you can use this guide to help you migrate your code over to the new methods. https://discordjs.guide/additional-info/changes-in-v14.html