Search code examples
javascriptnode.jsdiscorddiscord.jsws

Discord Api Valid intents must be provided for the Client but the code dosent work


I set up the

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

for my discord.js bot.

But now I just get the error message:

Uncaught c:\Users\niko\Documents\bot\receptionist\index.js:8

The line 8 in my index.js is this:

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

Solution

  • remove the first line of the code which states:

      
     const Discord = require('discord.js')
    

    and also delete the third line of the code which follows :

    const client= new Discord.Client()
    

    because you're declaring the client with the intents below after declaring the prefix. And also delete

    const bot = client