Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const client = new Discord.Client();
- const { readdir, lstatSync } = require('fs');
- const { token } = require('./config/config.json');
- client.commands = new Discord.Collection();
- client.aliases = new Discord.Collection();
- const loadCommands = module.exports.loadCommands = (dir = './src/commands/') => {
- readdir(dir, (error, files) => {
- if (error) return console.log(error);
- files.forEach((file) => {
- try {
- if (lstatSync(`${dir}${file}`).isDirectory()) {
- loadCommands(`${dir}${file}/`);
- } else if (file.endsWith('.js')) {
- const save = (name, aliases = [], props) => {
- client.commands.set(name, props);
- if (aliases.length > 0) aliases.forEach(alias => client.aliases.set(alias, props));
- console.log(`Command ${name} has saved | ${aliases.length} aliases`);
- };
- const props = require(`${dir}${file}`);
- if (!props.run) return console.log(`Command ${file.split('.')[0]} ignored because it has no function that activates it.`);
- if (props.info && props.info.name) {
- save(props.info.name, props.info.aliases || [], props);
- } else {
- if (!Object.keys(props)) return console.log(`Command ${file.split('.')[0]} ignored because it has no properties`);
- const filter = Object.keys(props).find(key => props[key] && props[key].name);
- if (!filter) return console.log(`Command ${file.split('.')[0]} ignored because it has no properties that refer to filename`);
- save(props[filter].name, props[filter].aliases || [], props);
- }
- }
- } catch (e) {
- console.log(`Error reading file ${file}`);
- console.log(e);
- }
- });
- });
- };
- loadCommands();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement