HamStudyBot/interactionCreate.js

30 lines
807 B
JavaScript
Raw Normal View History

2024-01-21 19:25:32 -05:00
const { readdirSync } = require('fs');
const registerCommands = (client) => {
client.commands = new Map();
const commandFiles = readdirSync('./commands').filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
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 });
}
});
};
module.exports = { registerCommands };