generated from nhcarrigan/template
feat: migrate from github
This commit is contained in:
55
src/modules/interactions/handleChatInputCommand.ts
Normal file
55
src/modules/interactions/handleChatInputCommand.ts
Normal file
@ -0,0 +1,55 @@
|
||||
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"].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}\``
|
||||
});
|
||||
}
|
||||
};
|
42
src/modules/interactions/handleContextMenuCommand.ts
Normal file
42
src/modules/interactions/handleContextMenuCommand.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { ContextMenuCommandInteraction } from "discord.js";
|
||||
|
||||
import { ExtendedClient } from "../../interfaces/ExtendedClient";
|
||||
import { errorHandler } from "../../utils/errorHandler";
|
||||
import { isGuildContextInteraction } from "../validateGuildCommands";
|
||||
|
||||
/**
|
||||
* Handles the logic for running context commands.
|
||||
*
|
||||
* @param {ExtendedClient} bot The bot's Discord instance.
|
||||
* @param {ContextMenuCommandInteraction} interaction The interaction payload from Discord.
|
||||
*/
|
||||
export const handleContextMenuCommand = async (
|
||||
bot: ExtendedClient,
|
||||
interaction: ContextMenuCommandInteraction
|
||||
) => {
|
||||
try {
|
||||
if (!isGuildContextInteraction(interaction)) {
|
||||
await interaction.reply({
|
||||
content: "You can only use this in a server.",
|
||||
ephemeral: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
const context = bot.contexts.find(
|
||||
(c) => c.data.name === interaction.commandName
|
||||
);
|
||||
if (!context) {
|
||||
await interaction.reply({
|
||||
content: "That's not a valid context. Please contact Naomi.",
|
||||
ephemeral: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
await context.run(bot, interaction);
|
||||
} catch (err) {
|
||||
const id = await errorHandler(bot, "handle context menu command", err);
|
||||
await interaction.editReply({
|
||||
content: `Something went wrong. Please [join our support server](https://chat.naomi.lgbt) and provide this ID: \`${id}\``
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user