Discord Api Valid intents must be provided for the Client [duplicate]

I am programming a discord bot. When I try to run node. in the cmd I get this:

C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\client\Client.js:544 throw new TypeError('CLIENT_MISSING_INTENTS'); ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client. at Client._validateOptions (C:\Users\utente\Desktop\bouncerBot\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:544:13) at new Client (C:\Users\utente\Desktop\bouncerBot\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:73:10) at Object. (C:\Users\utente\Desktop\bouncerBot\main.js:2:16) ←[90m at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m ←[90m
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m ←[90m at internal/main/run_main_module.js:17:47←[39m {
[←[32mSymbol(code)←[39m]: ←[32m'CLIENT_MISSING_INTENTS'←[39m }

C:\Users\utente\Desktop\bouncerBot>node . C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\client\Client.js:544 throw new TypeError('CLIENT_MISSING_INTENTS'); ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client. at Client._validateOptions (C:\Users\utente\Desktop\bouncerBot\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:544:13) at new Client (C:\Users\utente\Desktop\bouncerBot\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:73:10) at Object. (C:\Users\utente\Desktop\bouncerBot\main.js:3:16) ←[90m at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m ←[90m
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m ←[90m at internal/main/run_main_module.js:17:47←[39m {
[←[32mSymbol(code)←[39m]: ←[32m'CLIENT_MISSING_INTENTS'←[39m

I tried to search online for solutions but found nothing. I also activated the following potions in the bot settings but nothing changes:

enter image description here

This is my code, even if it is not the cause of the error:

Main.js:

   const Discord = require('discord.js');
    const fs = require('fs');
    const client = new Discord.Client();
    
    let rawdata = fs.readFileSync('config.json');
    let config = JSON.parse(rawdata);
    
    const TOKEN = config.botToken
    const prefix = config.prefix
    
    client.login(TOKEN)
    client.on('message', message => {
        if (!message.content.startsWith(prefix) || message.author.bot) return;
        const args = message.content.slice(prefix.lenght).split(/ +/)
        const command = args[1].toLowerCase()
        console.log(args)
        //Command test!
    })
    
    client.once('ready', () => {
        console.log("Discord bot online")
    
    });

config.json:

{
    "botToken":"",
    "prefix":"!pgc"
}

Edit:

I tried to update the code as follows:

    const Discord = require('discord.js');
    const fs = require('fs');
    
    const { Client, Intents } = require('discord.js');
    
    const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
    
    let rawdata = fs.readFileSync('config.json');
    let config = JSON.parse(rawdata);
    
    const TOKEN = config.botToken
    const prefix = config.prefix
    
    
    client.on('message', message => {
        if (!message.content.startsWith(prefix) || message.author.bot) return;
        const args = message.content.slice(prefix.lenght).split(/ +/)
        const command = args[1].toLowerCase()
        console.log(args)
        //Command test!
    })
    
    client.once('ready', () => {
        console.log("Discord bot online")
    
    });
client.login(TOKEN)

But I still get an error:

(node:12216) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined at RequestHandler.execute (C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\rest\RequestHandler.js:172:15) at RequestHandler.execute (C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\rest\RequestHandler.js:176:19) at RequestHandler.push (C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\rest\RequestHandler.js:50:25) at async WebSocketManager.connect (C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9) at async Client.login (C:\Users\utente\Desktop\bouncerBot\node_modules\discord.js\src\client\Client.js:245:7) (Use node --trace-warnings ... to show where the warning was created) (node:12216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:12216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


Solution 1:

First of all, never show a token of your bot, or try to change it later.

Second of all:

Try using this. Since new updated of discord.js like version ^13.0 you have to specify client intents:

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

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

And obviously, put client.login(TOKEN) at the very bottom.

For more updates required from new version of discord.js click here