celestine/src/modules/interactions/handleChatInputCommand.ts
Naomi Carrigan a4fdcbeddb
All checks were successful
Node.js CI / Lint and Test (push) Successful in 1m22s
Code Analysis / SonarQube (push) Successful in 1m41s
fix: allow non-mods to use birthday
2025-04-01 10:47:17 -07:00

62 lines
1.8 KiB
TypeScript

import { ChatInputCommandInteraction } from "discord.js";
import { ExtendedClient } from "../../interfaces/ExtendedClient";
import { errorHandler } from "../../utils/errorHandler";
import { isModerator } from "../../utils/isModerator";
import { isGuildCommandInteraction } from "../validateGuildCommands";
/**
* Handles the logic for running slash commands.
*
* @param {ExtendedClient} bot The bot's Discord instance.
* @param {ChatInputCommandInteraction} interaction The interaction payload from Discord.
*/
export const handleChatInputCommand = async (
bot: ExtendedClient,
interaction: ChatInputCommandInteraction
) => {
try {
if (!isGuildCommandInteraction(interaction)) {
await interaction.reply({
content: "You can only use commands in a server.",
ephemeral: true
});
return;
}
const command = bot.commands.find(
(c) => c.data.name === interaction.commandName
);
if (!command) {
await interaction.reply({
content: "That's not a valid command. Please contact Naomi.",
ephemeral: true
});
return;
}
if (
(!interaction.member || !isModerator(interaction.member)) &&
![
"leaderboard",
"rank",
"profile",
"role",
"help",
"ping",
"birthday"
].includes(interaction.commandName)
) {
await interaction.reply({
content: "You must be a moderator to use bot commands.",
ephemeral: true
});
return;
}
await command.run(bot, interaction);
} catch (err) {
const id = await errorHandler(bot, "handle chat input command", err);
await interaction.editReply({
content: `Something went wrong. Please [join our support server](https://chat.naomi.lgbt) and provide this ID: \`${id}\``
});
}
};