Discord API valid intents must be provided for the client

Total
0
Shares

I am programming a Discord bot. When I try to run a node, I get this in the CMD window:

C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcclientClient.js:544
throw new TypeError(‘CLIENT_MISSING_INTENTS’);
^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for
the Client.
at Client._validateOptions (C:UsersutenteDesktopbouncerBotnode_modules←[4mdiscord.js←[24msrcclientClient.js:544:13)
at new Client (C:UsersutenteDesktopbouncerBotnode_modules←[4mdiscord.js←[24msrcclientClient.js:73:10)
at Object. (C:UsersutenteDesktopbouncerBotmain.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:UsersutenteDesktopbouncerBot>node .
C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcclientClient.js:544
throw new TypeError(‘CLIENT_MISSING_INTENTS’);
^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for
the Client.
at Client._validateOptions (C:UsersutenteDesktopbouncerBotnode_modules←[4mdiscord.js←[24msrcclientClient.js:544:13)
at new Client (C:UsersutenteDesktopbouncerBotnode_modules←[4mdiscord.js←[24msrcclientClient.js:73:10)
at Object. (C:UsersutenteDesktopbouncerBotmain.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 I didn’t find anything. 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:

File 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")
});

File config.json:

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

I also 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:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcrestRequestHandler.js:172:15)
at RequestHandler.execute (C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcrestRequestHandler.js:176:19)
at RequestHandler.push (C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcrestRequestHandler.js:50:25)
at async WebSocketManager.connect (C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:128:9)
at async Client.login (C:UsersutenteDesktopbouncerBotnode_modulesdiscord.jssrcclientClient.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

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

Second of all:

Try using this. Since the new updated version 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, see What’s new.

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *