The console keeps showing this error, the path is 100% correct. Did I write something wrong? Please help!
const prefix = require('./config.json');
module.exports = {
name: 'say',
description: '...',
execute(message, args) {
const repeated = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
message.channel.send(repeated);
},
};
Here's my folder structure:
Judging by the image you provided, your running script, say.js
is located in: /command/say.js
.
./config.json
will look for the JSON file in /command/config.json
, which as we clearly can see, config.json
is not located there.
You need to go one folder up (current folder > root folder).
const configuration = require("../config.json");
./
references the current directory of the file it is written in. In this case, the commands
folder. However, ../
will act on the directory above the current directory. In your situation, this is the directory with the config.json
file.
Simply change:
require('./config.json')
To:
require('../config.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.