Files
ECS-FullStack/discord-bot/index.js
2025-10-02 17:31:49 -04:00

34 lines
936 B
JavaScript

const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const commandHandler = require('./handlers/command-handler');
const eventHandler = require('./handlers/event-handler');
commandHandler(client);
eventHandler(client);
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
const login = () => {
client.login(process.env.DISCORD_BOT_TOKEN);
}
module.exports = { login, client };