Files
blitzkit/src/behaviors/interactionCreate.ts
T

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-04-20 13:37:10 +00:00
import {
CacheType,
2023-04-26 00:02:10 +00:00
ChatInputCommandInteraction,
2023-04-20 13:37:10 +00:00
Collection,
Interaction,
RESTPostAPIChatInputApplicationCommandsJSONBody,
SlashCommandBuilder,
} from 'discord.js';
export interface CommandSet {
commandCollection: Collection<string, CommandRegistry>;
guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[];
publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[];
}
2023-04-20 14:09:22 +00:00
2023-04-20 13:37:10 +00:00
export interface CommandRegistry {
2023-04-26 00:02:10 +00:00
inDevelopment: boolean; // register with Skilled Bot (default: false)
inProduction: boolean; // register with Skilled Canary (default: false)
inPublic: boolean; // registers on all servers (default: true)
command: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
execute: (
interaction: ChatInputCommandInteraction<CacheType>,
commandSed: CommandSet,
) => void;
2023-04-20 13:37:10 +00:00
}
export default function interactionCreateCurry(commandSet: CommandSet) {
return async function interactionCreate(interaction: Interaction<CacheType>) {
if (!interaction.isChatInputCommand()) return;
const command = commandSet.commandCollection.get(interaction.commandName);
2023-04-20 13:37:10 +00:00
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`,
);
return;
2023-04-26 00:02:10 +00:00
}
try {
command.execute(interaction, commandSet);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
ephemeral: true,
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
2023-04-20 13:37:10 +00:00
}
};
2023-04-20 13:37:10 +00:00
}