30 lines
807 B
JavaScript
30 lines
807 B
JavaScript
|
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 };
|