I'm wanting to pass my bot's configuration file (config.json) into the bot client so I can get for example, the bot's owner ID instead of specifying it in each command that I want only the bot owner to access, or the embed footer text, example:
async execute(client, message, args, footerTxt) {
if (message.author.id == BotOwnerId) {
I want to be able to just have it be
async execute(client, message, args){
if (message.author.id == client.config.ownerID) {
I have tried running it through the command execute
try {
await client.commands.get(command).execute(client, message, args, footerTxt, config);
} catch (error) {
which resulted in
TypeError: Cannot read properties of undefined (reading 'ownerID')
at Object.execute
config.json
{
"ownerID": "XXXXXXXXXXX",
"someOtherStuff": [],
"someMoreStuff": { "id": 1, "name": "Test" }
}
index (assuming config.json is in the same folder)
const config = require('./config.json')
await client.commands.get(command).execute(client, message, args, footerTxt, config);
cmd:
if (message.author.id == config.ownerID) {
Why not simply requiring the config file in index and passing it through the args to the command? Or require it in the commands? As you wish but it should do the trick