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';
|
|
|
|
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-16 09:18:39 +02:00
|
|
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
|
|
|
|
|
|
|
// Load commands from the commands folder
|
|
|
|
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) {
|
|
|
|
const filePath = path.join(commandsPath, file);
|
2022-06-17 01:25:05 +02:00
|
|
|
let command = await import(filePath);
|
|
|
|
command = command.default;
|
2022-06-16 09:18:39 +02:00
|
|
|
|
|
|
|
client.commands.set(command.data.name, command);
|
|
|
|
}
|
|
|
|
|
2022-06-17 02:08:26 +02:00
|
|
|
// Load client events from the events folder
|
|
|
|
const clientEventsPath = path.join(__dirname, 'events/client');
|
|
|
|
const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js'));
|
2022-06-16 09:18:39 +02:00
|
|
|
|
2022-06-17 02:08:26 +02:00
|
|
|
for (const file of clientEventFiles) {
|
|
|
|
const filePath = path.join(clientEventsPath, file);
|
2022-06-17 01:25:05 +02:00
|
|
|
let event = await import(filePath);
|
|
|
|
event = event.default;
|
2022-06-16 09:18:39 +02:00
|
|
|
if (event.once) {
|
|
|
|
client.once(event.name, (...args) => event.execute(...args));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
client.on(event.name, (...args) => event.execute(...args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 02:08:26 +02:00
|
|
|
// Load process events from the events folder
|
|
|
|
const processEventsPath = path.join(__dirname, 'events/process');
|
|
|
|
const processEventFiles = fs.readdirSync(processEventsPath).filter(file => file.endsWith('.js'));
|
|
|
|
|
|
|
|
for (const file of processEventFiles) {
|
|
|
|
const filePath = path.join(processEventsPath, file);
|
|
|
|
let event = await import(filePath);
|
|
|
|
event = event.default;
|
|
|
|
if (event.once) {
|
|
|
|
process.once(event.name, (...args) => event.execute(...args));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
process.on(event.name, (...args) => event.execute(...args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 09:18:39 +02:00
|
|
|
client.login(token);
|