Split into multiple files #18

Merged
Anri merged 22 commits from dev into main 2022-07-03 18:43:31 +02:00
Showing only changes of commit 3d0fe87717 - Show all commits

View file

@ -1,31 +1,24 @@
const fs = require('node:fs'); const { Client, Intents } = require('discord.js');
const path = require('node:path');
const { Client, Collection, Intents } = require('discord.js');
const { token } = require('../config/config.json');
const run = async () => {
console.log('Starting Botanique...');
// Load .env if not in prod
if (process.env.NODE_ENV !== 'production') {
const dotenv = await import('dotenv');
dotenv.config({ path: './config/.env' });
}
// Client Discord.JS
const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.config = { token_discord: process.env.TOKEN_DISCORD };
/* EVENT */ if (client) {
const eventsPath = path.join(__dirname, 'events'); console.log('Client ✅');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(path.join(eventsPath, file));
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else { } else {
client.on(event.name, async (...args) => event.execute(...args)); throw 'Client ❌';
}
} }
/* COMMANDS */ await client.login(client.config.token_discord);
client.commands = new Collection(); };
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) { run().catch(error => console.error(error));
const command = require(path.join(commandsPath, file));
client.commands.set(command.data.name, command);
}
client.login(token);