for (const file of eventFiles) {
const event = require(path.join(eventsDir, file));
if (event.once) {
console.log(event.name)
bot.once(event.name, (...args) => event.execute(...args));
} else {
console.log(event.name)
bot.on(event.name, (...args) => event.execute(...args));
}
}
bot.commands = new Map();
const slashCommandFiles = fs.readdirSync(slashCommandsDir).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(path.join(slashCommandsDir, file));
bot.commands.set(command.name, command);
}
bot.on('interactionCreate', async (interaction) => {
console.log(interaction);
if (!interaction.isCommand()) return;
const command = bot.commands.get(interaction.data.name);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.log(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}
});
for (const file of eventFiles) {
const event = require(path.join(eventsDir, file));
if (event.once) {
console.log(event.name)
bot.once(event.name, (...args) => event.execute(...args));
} else {
console.log(event.name)
bot.on(event.name, (...args) => event.execute(...args));
}
}
bot.commands = new Map();
const slashCommandFiles = fs.readdirSync(slashCommandsDir).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(path.join(slashCommandsDir, file));
bot.commands.set(command.name, command);
}
bot.on('interactionCreate', async (interaction) => {
console.log(interaction);
if (!interaction.isCommand()) return;
const command = bot.commands.get(interaction.data.name);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.log(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}
});