2022-06-17 01:25:05 +02:00
|
|
|
import fs from 'node:fs';
|
|
|
|
import path from 'node:path';
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { Client, Collection, Intents } from 'discord.js';
|
2022-06-17 02:14:14 +02:00
|
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
2022-06-16 09:18:39 +02:00
|
|
|
const { token } = process.env;
|
|
|
|
|
2022-06-17 01:25:05 +02:00
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
2022-06-20 11:42:20 +02:00
|
|
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS], shards: 'auto' });
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
// Load commands
|
2022-06-16 09:18:39 +02:00
|
|
|
client.commands = new Collection();
|
2022-06-17 07:31:58 +02:00
|
|
|
await loadCommandFromDir('fun');
|
|
|
|
await loadCommandFromDir('utility');
|
2022-08-15 17:23:23 +02:00
|
|
|
await loadCommandFromDir('admin');
|
2022-06-20 11:42:20 +02:00
|
|
|
await loadCommandFromDir('owner');
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
// Load events
|
2022-06-20 11:42:20 +02:00
|
|
|
await loadEventFromDir('client', client);
|
|
|
|
await loadEventFromDir('process', process);
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
client.login(token);
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
async function loadCommandFromDir(dir) {
|
|
|
|
const commandsPath = path.join(`${__dirname}/commands`, dir);
|
|
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
for (const file of commandFiles) {
|
|
|
|
const filePath = path.join(commandsPath, file);
|
|
|
|
let command = await import(filePath);
|
|
|
|
command = command.default;
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
client.commands.set(command.data.name, command);
|
2022-06-17 02:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 07:31:58 +02:00
|
|
|
async function loadEventFromDir(dir, listener) {
|
|
|
|
const eventsPath = path.join(`${__dirname}/events`, dir);
|
|
|
|
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
|
|
|
|
|
|
|
for (const file of eventFiles) {
|
|
|
|
const filePath = path.join(eventsPath, file);
|
|
|
|
let event = await import(filePath);
|
|
|
|
event = event.default;
|
|
|
|
if (event.once) {
|
2022-08-15 17:23:23 +02:00
|
|
|
listener.once(event.name, (...args) => event.execute(...args, client));
|
2022-06-17 07:31:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-08-15 17:23:23 +02:00
|
|
|
listener.on(event.name, (...args) => event.execute(...args, client));
|
2022-06-17 07:31:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|