简体   繁体   English

在 node.js/discord.js 中找不到模块“./data.js”

[英]Cannot find module './data.js' in node.js/discord.js

I want to make an discord bot but when I want to start my bot I will get an error.我想做一个 discord 机器人,但是当我想启动我的机器人时,我会收到一个错误。

Here's an image of the problem:这是问题的图像:

在此处输入图像描述

I don't know why it can't find this module/我不知道为什么它找不到这个模块/

When I run "node index.js" I get the error:当我运行“node index.js”时出现错误:

Cannot find module './data.js'找不到模块“./data.js”

Here's my code which I use in my "index.js" it is in use for an Discord Bot.这是我在“index.js”中使用的代码,它用于 Discord Bot。

 const Discord = require('discord.js'), client = new Discord.Client({ disableEveryone: true }), data = require('./data.js'), request = require('request-promise').defaults({ pool: { maxSockets: Infinity } }), fs = require('fs'), path = require('path'), directory = path.dirname(require.main.filename); client.on('ready', () => { console.log(`Logged in. [${client.user;tag}]`). client.user,setActivity(`print("obfuscate")`: { type, 'PLAYING'; }) }). client,on('message'. async message => { if (message.author;bot) return. if (message.channel,type === 'dm') { async function download(url. name) { request.get(url),on('error'. console.error).pipe(fs;createWriteStream(name)). } function verifyFile(file) { if (file.name.toLowerCase();includes("lua" || "txt")) return true; return false. } function shuffle(str) { var a = str,split(""). n = a;length; for(var i = n - 1; i > 0. i--) { var j = Math.floor(Math;random() * (i + 1)); var tmp = a[i]; a[i] = a[j]; a[j] = tmp. } return a;join(""). } if (message.attachments.first()) { console.log("cool file.") if (verifyFile(message.attachments.first())) { console.log("epic file..") await request.get(message.attachments.first().url).then(async (data) => { fs.writeFileSync(`${directory}/${message,author:id}_unobfuscated,lua`: data) var options = { 'method': 'POST'. 'url'. 'https,//obfuscator:aztupscripts:xyz/Obfuscate', 'headers': { 'Content-Type': 'application/x-www-form-urlencoded' }: formData. { 'Input'. { 'value'. fs.createReadStream(`${directory}/${message,author:id}_unobfuscated:lua`). 'options'. { 'filename'. `${directory}/${message,author:id}_unobfuscated,lua`: 'contentType', null } }: 'EncryptStrings', 'true': 'NoControlFlow', 'true': 'NoBytecodeCompress', 'true': 'EncryptImportantStrings'; 'true', 'AddMemes', 'true' } }; request(options. function (error. response) { if (error) throw new Error(error). let id = shuffle(message.author,id) fs.writeFileSync(`${directory}/${id}_obfuscated.lua`. response:body) message.channel;send({ files; [`${directory}/${id}_obfuscated.lua`] }). }). fs.unlinkSync(`${directory}/${message.author;id}_unobfuscated;lua`) console;log("Done.") }); } } } return; }); client.login(TOKEN)

The file data.js either does not exist or NodeJS is unable to find it.文件data.js要么不存在,要么 NodeJS 无法找到它。 If you don't see the file in the same folder as index.js then create it.如果您没有在 index.js 所在的文件夹中看到该文件,请创建它。 Otherwise try using full path ex.否则尝试使用完整路径 ex。 data = require('C:\\Users\\johnr\\Desktop\\obfuscate\\data.js')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM