我一直收到這個錯誤,有人可以幫助我嗎?
- index.js
const Discord = require('discord.js');
const client = new Discord.Client();
const client = new client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('The Bot is online!');
});
client.login('Token');
- 錯誤
SyntaxError: Identifier 'client' has already been declared
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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:81:12)
at node:internal/main/run_main_module:17:47
- 包.json
{
"name": "krabbymusic",
"version": "1.0.0",
"description": "KrabbyMusic is a Discord Music Bot that will replace the Rythm-Bot",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "drk",
"license": "ISC",
"dependencies": {
"@discordjs/opus": "^0.7.0",
"discord.js": "^13.6.0",
"ffmpeg-static": "^4.4.1",
"yt-search": "^2.10.3",
"ytdl-core": "^4.10.0"
}
}
到目前為止,我已經嘗試了所有我發現的東西,但我無法修復它。
uj5u.com熱心網友回復:
錯誤來了,因為您已經client在第 2 行中宣告為常量,因此您無法在第 3 行中創建具有相同名稱的新常量。只需洗掉第 2 行并將第 3 行更改為const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS]})即可
uj5u.com熱心網友回復:
正如 Caladan 所說,您將 client 宣告為 a constant variable,即您無法更改此變數的值,這就是第 3 行所做的,這會導致錯誤。
下面的代碼在匯入模塊時使用解構功能更有效且更具可讀性。
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('The Bot is online!');
});
client.login('Token');
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/416710.html
標籤:
上一篇:通過將最后一個值與下一個索引中的第一個值匹配來對二維陣列進行排序
下一篇:倒數計時器-變數過期時隱藏
