【发布时间】:2021-08-24 18:51:48
【问题描述】:
我正在尝试制作一个不和谐的机器人,但我收到错误“ReferenceError: command is not defined”我不明白为什么,有人可以帮忙吗?
这是我的代码:
console.clear();
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES']});
const Client = require("./Structures/Client.js");
const config = require("./Data/config.json");
client.commands = new Discord.Collection();
const fs = require("fs");
fs.readdirSync("./src/Commands")
.filter((file) => file.endsWith(".js"))
.forEach((file) => {
/**
* @type {Command}
*/
const commands = require(`./Commands/${file}`);
console.log(`Command ${command.name} loaded`);
client.commands.set(command.name, command);
});
client.on("ready", () => console.log("SpidBot is online!"));
client.on("messageCreate", (message) => {
//console.log(message.content);
//if (message.content == "!Spid") message.reply("Hello!");
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.substring(config.prefix.length).split(/ +/);
const command = client.commands.find((cmd) => cmd.name == args[0]);
});
client.login(config.token);
这是错误:
C:\Users\Aly\Desktop\SpidBot\src\index.js:22
console.log(`Command ${command.name} loaded`);
^
ReferenceError: command is not defined
at C:\Users\Aly\Desktop\SpidBot\src\index.js:22:26
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\Aly\Desktop\SpidBot\src\index.js:17:3)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
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:79:12)
at node:internal/main/run_main_module:17:47
似乎还有一些错误,有人可以帮我解决它吗?
【问题讨论】:
标签: discord.js