当我运行 Node Index.js 时,我的 Node 应用程序不运行
文件index.js:
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '<my-token>';
bot.on('ready', () =>{
console.log('This bot is online!');
})
bot.login(token);
这是错误的堆栈跟踪:
Error: Cannot find module 'C:\Users\Thela\Desktop\Discord UWU\run'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11 {
最佳答案
看来您启动机器人的方式不正确。请务必执行node <path to bot main file>
例如
node "C:\Users\ExampleUser\Documents\ExampleBot\app.js"
, app.js 是您发布的文件。确保使用您自己的文件/路径将其全部切换
为了更简单,您还可以cd
到相应的文件夹并从那里运行 Node app.js。
关于javascript - 使用 Discord.js 时出现 "Error: Cannot find module",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58700953/