当我运行机器人时出现此错误
C:\Users\hp\Desktop\Bot>node .
C:\Users\hp\Desktop\Bot\src\my_bot.js:8
client.commands = new Discord.Collection();
^
ReferenceError: Discord is not defined
at Object.<anonymous> (C:\Users\hp\Desktop\Bot\src\my_bot.js:8:23)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m
my_bot.js https://sourceb.in/ZN42H2fCes
当我运行机器人时,我遇到了这个错误。我已经安装了 discord.js,但仍然出现这个错误。我也使用 ./src/my_bot.js 运行了机器人,但它仍然无法工作。谢谢你的帮助
答案 0 :(得分:1)
非常简单的解决方案。 不和谐未定义。
您可以改为定义 Collection
以要求 discord.js
,如下所示:
const { Client, Collection } = require('discord.js');
然后,您可以用以下内容替换该行:
client.commands = new Collection();