This repository has been archived on 2025-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tingle-bot/src/events/handlers/onInteraction.ts

37 lines
999 B
TypeScript

/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { commandList } from "../../commands/_commandList.js";
import type { WeatherCache } from "../../interfaces/weatherCache.js";
import type { Interaction } from "discord.js";
/**
* Handles the INTERACTION_CREATE event from Discord. Checks if the interaction is
* an application command, and if there is a matching command, and runs it.
* @param interaction - The interaction payload from Discord.
* @param cache - The cache of weather data.
*/
export const onInteraction = async(
interaction: Interaction,
cache: WeatherCache,
): Promise<void> => {
if (!interaction.isChatInputCommand()) {
return;
}
const target = commandList.find(
(command) => {
return command.data.name === interaction.commandName;
},
);
if (!target) {
await interaction.reply(`Command ${interaction.commandName} not found.`);
return;
}
await target.run(interaction, cache);
};