Files
pixelpoebel/src/index.ts
sarah ceaeabf57a
Some checks failed
Auto Build and Push Docker Image / build (push) Failing after 15s
Initialer Bot Upload
2026-03-21 00:24:19 +01:00

61 lines
2.1 KiB
TypeScript

import 'dotenv/config';
import { ExtendedClient } from './structures/ExtendedClient.js';
import { readdirSync } from 'node:fs';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join } from 'node:path';
import { Command } from './structures/Command.js';
import { DB } from './structures/Database.js';
import { TwitchManager } from './structures/TwitchManager.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Initialize Database
DB.init();
const client = new ExtendedClient();
// Start Twitch Polling
TwitchManager.startPolling(client);
// Load Commands
const commandsPath = join(__dirname, 'commands');
const commandFolders = readdirSync(commandsPath);
for (const folder of commandFolders) {
const folderPath = join(commandsPath, folder);
const commandFiles = readdirSync(folderPath).filter(file => file.endsWith('.ts') || file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = join(folderPath, file);
const fileUrl = pathToFileURL(filePath).href;
const command: Command = (await import(fileUrl)).default;
if (command && 'data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
console.log(`[COMMAND] Loaded: ${command.data.name}`);
} else {
console.warn(`[COMMAND] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
// Load Events
const eventsPath = join(__dirname, 'events');
const eventFiles = readdirSync(eventsPath).filter(file => file.endsWith('.ts') || file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = join(eventsPath, file);
const fileUrl = pathToFileURL(filePath).href;
const event = (await import(fileUrl)).default;
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
console.log(`[EVENT] Loaded: ${event.name}`);
}
client.login(process.env.DISCORD_TOKEN);