I am trying to add a command handler to my bot, however, only one command is working and no matter how I change the command, it does not update. Here is my code.
This is at the top underneath the packages and above the on ready code.
fs.readdir('./commands/', (_err, files) => {
files.forEach((file) => {
if (!file.endsWith('.js')) return;
bot.commands = new Discord.Collection()
let command = require(`./commands/${file}`); // access all details though this variable
bot.commands.set(command.name, command);
console.log(` Command loaded: ${command.name}`);
});
});
This is in the resources command
const Discord = require("discord.js")
const fs = require("fs")
module.exports = {
name: 'resources',
// any other details you might like, such as:
description: 'Shows resources',
execute(bot, message, args, prefix) {
// the actual function
let resourceText = fs.readFileSync('txtfiles/resources.txt', 'utf8')
message.suppressEmbeds(true)
message.channel.send(resourceText)
}
}
The resources command works just fine, but the ship command does not.
const Discord = require("discord.js")
const fs = require("fs")
module.exports = {
name: 'ship',
// any other details you might like, such as:
description: 'ships people',
execute(bot, message, args, prefix) {
// the actual function
message.channel.send("please work")
}
}
And this is in the "on messageCreate" thing
if(cmd===`${prefix}resources`){bot.commands.get('resources').execute(bot, message, args, prefix);}
if(cmd===`${prefix}ship`){bot.commands.get('ship').execute(bot, message, args, prefix);}
I have tried putting these underneath the packages
delete require.cache['./index.js'];
delete require.cache[require.resolve('./index.js')]
However, I am getting this error message
Unhandled promise rejection: TypeError: Cannot read properties of undefined (reading 'execute')
The resources command works just fine, even if we delete all the code in the file, and the ship command does not work at all.