[英]UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db' when i try to run my code
so i was trying to implement a database for my discord bot but when it try to call on it all i get is所以我试图为我的不和谐机器人实现一个数据库,但是当它尝试调用它时,我得到的只是
UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db' UnhandledPromiseRejectionWarning:错误:找不到模块“../database/db”
heres the bit thats failing这是失败的一点
const Discord = require('discord.js'); const bot = new Discord.Client(); const fs = require('fs'); const util = require('util'); const mysql = require('mysql2'); let connection; require('dotenv').config(); ///Token for discord bot (async () => { connection = await require('../database/db'); await bot.login(process.env.BOT_TOKEN); })();
and heres my file structure这是我的文件结构
i tried installing mysql2 globally to see if that work help and it didnt :(我尝试全局安装 mysql2 以查看该工作是否有帮助,但没有 :(
someone asked what the file inside database looked like有人问数据库里面的文件是什么样的
Because you didnt give us enough info i cant really help but if your file name your trying to get is db
and your file name is index.js then this should work因为你没有给我们足够的信息我真的帮不上忙但是如果你试图获取的文件名是
db
而你的文件名是 index.js 那么这应该可以工作
connection = await require('./database/db');
NOTE : if this doesnt work please add more screenshots / more info about your file locations注意:如果这不起作用,请添加更多屏幕截图/有关文件位置的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.