试图做出一些经济的命令,当前试图做出将消息作者拥有的硬币总数发送给消息作者的命令。我继续收到“无法找到模块”错误。我曾尝试搜索此错误,但似乎无法找到解决方案。
我的文件结构-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);
}
}
答案 0 :(得分:1)
根据您链接的文件结构,require
在coins.json
文件夹中寻找commands
,因为您只给文件名加上了../
一次。为了获取您的文件,请在名称前加上../../
,以使其位于两个文件夹中。您的行将如下所示:
let coins = require("../../coins.json");
答案 1 :(得分:0)
如果是由于错误的路径,则可以使用下面的代码。它将在您的代码中的任何位置找到json文件。
const { join } = require("path");
let coins = require(`${join(process.cwd(), "coins.json")}`);