diff options
| author | Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net> | 2026-04-22 22:49:01 +0200 |
|---|---|---|
| committer | Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net> | 2026-04-22 22:49:01 +0200 |
| commit | 3572b97661a3f7c6c29e958b63c20d9f2ef936ac (patch) | |
| tree | b3ee056039cf792edd467e5172feee25a07dd56c /index.js | |
initialise repository
Signed-off-by: Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net>
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 52 |
1 files changed, 52 insertions, 0 deletions
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é <eqilia@national.shitposting.agency> + * 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); + |
