【发布时间】:2023-01-02 20:16:57
【问题描述】:
代码:
require("dotenv").config();
const { token } = process.env;
const {client, collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");
const client = new Client({ intents: GatewayIntentBits.Guilds });
client.commands = new collection();
client.commandArray = [];
const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
const functionFiles = fs
.readdirSync('./src/functions/${folder}')
.filter((file) => file.endsWith(".js"));
for (const file of functionFiles)
require(`./functions/${folder}/${file}`)(client);
}
client.handleEvents();
client.handleCommands();
client.login(token);
运行 npm run test 后出错:
**const client = new Client({ intents: GatewayIntentBits.Guilds });
^
SyntaxError: Identifier 'client' has already been declared**
at Object.compileFunction (node:vm:360:18)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
我尝试删除第 3 行,因为客户端已在第 6 行处理,但这也会引发不同的错误。
有人可以建议吗?
我尝试删除第 3 行,因为客户端已在第 6 行处理,但这也会引发不同的错误。
尝试从第 3 行删除“客户端”
【问题讨论】:
-
当您从第 3 行仅删除 client 时会出现什么错误?
-
const client = new Client({ intents: GatewayIntentBits.Guilds }); ^ ReferenceError:客户端未定义
-
它可能应该是
Client而不是client在您的导入/要求中 -
同样适用于
Collection
标签: javascript