Today I encountered an error while trying to modify my command handler based on a YouTube video tutorial. The video was uploaded in April and the method worked for the creator, but unfortunately not for me. Despite my efforts, I couldn't find a solution to this issue. Although I am still learning, I am determined to begin my journey like many others in this incredible community that has been so supportive and helpful. Thank you for all the support! I remain optimistic that I will overcome this obstacle.
const Timeout = new Discord.Collection();
const bot = new Discord.Client();
const prefix = '$';
bot.commands = new Discord.Collection();
const commandFolders = readdirSync('./commands');
const ms = require('ms');
const {readdirSync , read} = require('fs');
for(const folder of commandsFolders){
const commandFiles = readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${folder}/${files}`);
bot.commands.set(command.name, command);
}
}
bot.on("error" , console.error);
bot.once('ready' , () => {
console.log('I have risen from the dead!');
});
bot.on("message" , async (message) =>{
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
if(message.content.startsWith(prefix)){
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = bot.command.get(commandName) || bot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if(!command) return;
if (command) {
if(command.cooldown){
if(Timeout.has(`${command.name}${message.author.id}`)) return message.channel.send(`Please wait! \`${ms(Timeout.get (`${command.name}${message.author.id}`) - Date.now(), {long: true})}\`Before using this command again!`);
command.run(bot, message, args)
Timeout.set(`${command.name}${message.author.id}` , Date.now() + command.cooldown)
setTimeout(() =>{
Timeout.delete(`${coomand.name}${message.author.id}`)
}, command.cooldown)
} else command.run(bot, message, args);
}
}
})