[英]Cant find module
尝试发出一些经济命令,目前正在尝试发出将消息作者拥有的硬币总量发送给消息作者的命令。 我继续收到“找不到模块”错误。 我已尝试搜索此错误,但我似乎无法找到解决方案。
我的文件结构 - https://i.stack.imgur.com/sER3g.png
const { RichEmbed } = require("discord.js");
let coins = require("../coins.json");
module.exports = {
name: "coins",
descriptions: "shows how many coins you have",
category: "Economy",
run: async (client, message, args) => {
//coins
if(!coins[message.author.id]){
coins[message.author.id] = {
coins: 0
};
}
let uCoins = coins[message.author.id].coins;
let coinEmbed = new RichEmbed()
.setAuthor(message.author.username)
.setcolor("RANDOM")
.addField("💸", uCoins);
message.author.send(coinEmbed);
}
}
根据您链接的文件结构,您的require
是在commands
文件夹中查找coins.json
,因为您只在文件名前加上../
一次。 为了获取您的文件,请在名称前加上../../
,这样它就会上升两个文件夹。 您的行将如下所示:
let coins = require("../../coins.json");
如果是由于路径不正确,您可以使用下面的代码。 它会在代码中的任何位置找到 json 文件。
const { join } = require("path");
let coins = require(`${join(process.cwd(), "coins.json")}`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.