import fs from 'node:fs'; import path from 'node:path'; import { Client, Collection, Events, GatewayIntentBits } from 'discord.js'; import dotenv from 'dotenv'; dotenv.config(); const token = process.env.DISCORD_KEY as string; import express from 'express'; const app = express(); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); declare module "discord.js" { export interface Client { commands: Collection, api_key: Collection } } client.commands = new Collection(); client.api_key = new Collection(); const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); } } } client.once(Events.ClientReady, readyClient => { console.log(`Ready! Logged in as ${readyClient.user.tag}`); }); client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); if (!command) { console.error(`No command matching ${interaction.commandName} was found.`); return; } try { await command.execute(interaction); } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); } else { await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } } }); client.login(token); app.get('/', (req, res) => { res.send('Hello World!'); }) app.listen(7860, "0.0.0.0",async () => { console.log("Listening on port 7860"); })