Home > front end >  SyntaxError: Identifier 'client' has already been declared [closed]
SyntaxError: Identifier 'client' has already been declared [closed]

Time:09-26

im tryna make a discord bot. whenever i try to run it with cmd i get this:

error in cmd:

C:\Users\kaalj\OneDrive\Desktop\Bot>node main.js
C:\Users\kaalj\OneDrive\Desktop\Bot\main.js:7
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
      ^

SyntaxError: Identifier 'client' has already been declared
←[90m    at wrapSafe (internal/modules/cjs/loader.js:988:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1036:27)←[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

the code i got this far is: Package.json

{
  "name": "gerda",
  "version": "1.0.0",
  "description": "Gerda",
  "main": "= main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Jordy",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^13.1.0"
  }
}

main.js:

const Discord = require('discord.js');

const client = new Discord.Client();

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

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

client.once('ready', () => {
  console.log('Gerda is er');
});

client.login("Token");

anyone knows what i have to do to make it run? (in my code i actually have my token filled in)

CodePudding user response:

You just need to remove the client declared at line number 3. You have already handled it in line 7 in detail. So delete line 3 and you're good.

CodePudding user response:

as you can see on lines: 3 and 7 , on both you declared const which is called: client.

it is that simple.

  • Related