javascript - 使用 Discord.js 时出现 "Error: Cannot find module"

标签 javascript node.js discord discord.js

当我运行 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/

相关文章:

node.js - 将 objectID 列为选择值并保存表单

python - 当我提到它时,让机器人用前缀进行响应

discord - 我正在尝试使用 discord.py 构建歌词命令,但出现此错误。关于我做错了什么以及如何修复它有什么想法吗?

javascript - 使 div 浮在其他内容上

javascript - 如何在此代码上实现 jQuery cookie

javascript - 淡入淡出的 Bootstrap 警报不起作用

javascript - 语法 var names = string.split ("\n"), make\r behind element of string field

javascript变量包含而不是等于

node.js - 在 Windows Node.js 中使用 unix 文件行为

javascript - 抓取 JS 渲染页面的方法?