I am making a discord bot with Node.js and discord.js. and I type node index.js and it said:
const client = new Discord.Client({
^
SyntaxError: Identifier 'client' has already been declared
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
What to do?
my index.js:
const { client, GatewayIntentBits } = require("discord.js");
const config = require("./config.json");
const client = new Discord.Client({
intents: [
GatewayIntentBIts.Guilds,
GatewayIntentBits.GuildMessages
]});
clien.login(config.BOT_TOKEN);
My config.json:
{
"BOT_TOKEN": "MY BOT TOKEN"
}
I am using neovim
My discord.js version is 14.6.0
CodePudding user response:
I saw that you have misspelled Client
. Use this instead.
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBIts.Guilds,
GatewayIntentBits.GuildMessages
]});
CodePudding user response:
**you need to change the variable name in 4th line from client to another name **
const { client, GatewayIntentBits } = require("discord.js");
const config = require("./config.json");
const client = new Discord.Client({ //change here variable name another from client
intents: [
GatewayIntentBIts.Guilds,
GatewayIntentBits.GuildMessages
]});
clien.login(config.BOT_TOKEN);