better-npm-init
Version:
A better version of npm init, with templates and more. Usage: better-npm-init <template> [--yarn] [--install] [--git] [--yes] [--help]
52 lines (40 loc) • 1.81 kB
JavaScript
const { prefix, token } = require("./config.json");
const { Client, Intents, Collection } = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });
const fs = require("fs");
bot.commands = new Collection();
const commandFiles = fs.readdirSync('./commands/').filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${file}`)
console.log(`${file} loaded`)
bot.commands.set(props.help.name, props)
}
const commandSubFolders = fs.readdirSync('./commands/').filter(f => !f.endsWith('.js'))
commandSubFolders.forEach(folder => {
const commandFiles = fs.readdirSync(`./commands/${folder}/`).filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${folder}/${file}`)
console.log(`${file} loaded from ${folder}`)
bot.commands.set(props.help.name, props)
}
});
const eventFiles = fs.readdirSync('./events/').filter(f => f.endsWith('.js'))
for (const file of eventFiles) {
const event = require(`./events/${file}`)
if (event.once) {
bot.once(event.name, (...args) => event.execute(...args, bot))
} else {
bot.on(event.name, (...args) => event.execute(...args, bot))
}
}
bot.on("messageCreate", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if (!cmd.startsWith(prefix)) return;
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if (commandfile) commandfile.run(bot, message, args);
});
bot.login(token);