/* * Copyright (C) 2024 Emilia Luminé * This file is a part of the Amygdala bot. */ const path = require('node:path'); const fs = require('node:fs'); const dotenv = require('dotenv'); const { Client, GatewayIntentBits, Partials } = require('discord.js'); globalThis.config = require('./config.json'); dotenv.config({ quiet: true }); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent ] }); globalThis.client = client; globalThis.reloadEvents = () => { client.removeAllListeners(); const eventsDir = fs.readdirSync(config.directories.eventsDir).filter((fileName) => fileName.endsWith('.js')); for (let i = 0; i < eventsDir.length; i += 1) { const eventModulePath = path.join(process.cwd(), config.directories.eventsDir, eventsDir[i]); const eventModule = require(eventModulePath); if (typeof eventModule.name !== 'string' || typeof eventModule.execute !== 'function') { console.error(`${eventModulePath} is not a valid event module`); break; } console.log(`${eventModule.name}`); client.on(eventModule.name, eventModule.execute); } } process.on('unhandledRejection', async (a) => { console.error(a); }); globalThis.reloadEvents(); client.login(process.env.DISCORD_BOT_TOKEN);