[英]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.