首页 > 解决方案 > 找不到模块

问题描述

尝试发出一些经济命令,目前正在尝试发出将消息作者拥有的硬币总量发送给消息作者的命令。我继续收到“找不到模块”错误。我已尝试搜索此错误,但我似乎无法找到解决方案。

我的文件结构 - 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);
    }
}

标签: javascript

解决方案


根据您链接的文件结构,您require正在寻找文件夹coins.json中的commands,因为您只在文件名前加上../一次。为了获取您的文件,请在名称前加上../../,因此它会上升两个文件夹。您的行将如下所示:

let coins = require("../../coins.json");

推荐阅读