god damn if this works the whole way

This commit is contained in:
2025-12-15 14:17:07 -05:00
parent eeac64563e
commit c9b2453b1c
5 changed files with 338 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
const config = require('./config.json');
// the basic discord setup stuff yoinked from their guide
const { Client, Events, GatewayIntentBits, Partials, ActivityType, MessageFlags } = require('discord.js');
const { Client, Events, GatewayIntentBits, Partials, ActivityType, MessageFlags, Collection } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
@@ -152,3 +152,39 @@ client.on(Events.MessageReactionAdd, (reaction, user) => {
}
})
// command handling for ./commands
const fs = require('fs');
const path = require('node:path');
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
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);
console.debug(`Commands: Registered "${command.data.name}"`);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
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 {
console.debug(`Command: Executing ${interaction.commandName}`);
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!', flags: MessageFlags.Ephemeral });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', flags: MessageFlags.Ephemeral });
}
}
});