From 3572b97661a3f7c6c29e958b63c20d9f2ef936ac Mon Sep 17 00:00:00 2001 From: Amygdala Peanut-Almond Date: Wed, 22 Apr 2026 22:49:01 +0200 Subject: initialise repository Signed-off-by: Amygdala Peanut-Almond --- index.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 index.js (limited to 'index.js') diff --git a/index.js b/index.js new file mode 100644 index 0000000..57c1091 --- /dev/null +++ b/index.js @@ -0,0 +1,52 @@ +/* + * 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); + -- cgit 1.4.1