Trying to make some economy commands, currently trying to make the command that sends the total amount of coins, the message author has, to the message author. i continue to get "cant find module" errors. i have tried searching for this error, but i seem to not be able to find a solution.
My file construct - 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);
}
}
As per the file structure you linked, your require
is looking for the coins.json
in the commands
folder, as you only prefixed the file name with ../
once. In order to get your file, prefix the name with ../../
, so it goes up two folders. Your line would then look like this:
let coins = require("../../coins.json");
If it is due to incorrect path you can use the code bellow. It will find the json file anywhere in your code.
const { join } = require("path");
let coins = require(`${join(process.cwd(), "coins.json")}`);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.