Minimalistic slash command library for Discord.js.
It is recommended that you use @typicalbot/events with this library. However, we have provided an example if you choose not to use @typicalbot/events.
import EventHandler from '@typicalbot/events';
const SlashCommandHandler: EventHandler<'interactionCreate'> = async (client, interaction) => {
if (interaction.isCommand()) return;
const name = interaction.commandName;
if (client.commands.has(name)) return; // This is a Collection of commands
try {
await client.commands.get(name)?.(client, interaction);
} catch {
await interaction.reply({
content: 'An error occurred while trying to execute that command.'
});
}
}
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) return;
const name = interaction.commandName;
if (client.commands.has(name)) return; // This is a Collection of commands
try {
await client.commands.get(name)?.(client, interaction);
} catch {
await interaction.reply({
content: 'An error occurred while trying to execute that command.'
});
}
});
TypicalBot Commands is an open source software licensed under the Apache 2.0 license.