generated from nhcarrigan/template
feat: add /announcement owner-only slash command
Triggers a modal with a content text input and category select menu, calls the announcement API, DMs generated copy as file attachments, and replies ephemerally with the platform recap.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ModalBuilder,
|
||||
StringSelectMenuBuilder,
|
||||
TextInputBuilder,
|
||||
TextInputStyle,
|
||||
} from "discord.js";
|
||||
import { entitledUsers } from "../config/entitlements.js";
|
||||
import { errorHandler } from "../utils/errorHandler.js";
|
||||
import type { Command } from "../interfaces/command.js";
|
||||
|
||||
/**
|
||||
* Handles the `/announcement` command interaction.
|
||||
* Owner-only command that opens a modal for creating cross-platform announcements.
|
||||
* @param _hikari - Hikari's Discord instance (unused).
|
||||
* @param interaction - The command interaction payload from Discord.
|
||||
*/
|
||||
export const announcement: Command = async(_hikari, interaction) => {
|
||||
try {
|
||||
if (!entitledUsers.includes(interaction.user.id)) {
|
||||
await interaction.reply({
|
||||
content: "This command is restricted to the owner.",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const modal = new ModalBuilder().
|
||||
setCustomId("announcement_modal").
|
||||
setTitle("Create Announcement");
|
||||
|
||||
const contentInput = new TextInputBuilder().
|
||||
setCustomId("content").
|
||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal text input labels
|
||||
setLabel("Announcement Copy").
|
||||
setStyle(TextInputStyle.Paragraph).
|
||||
setMaxLength(4000).
|
||||
setRequired(true);
|
||||
|
||||
const categorySelect = new StringSelectMenuBuilder().
|
||||
setCustomId("category").
|
||||
setPlaceholder("Select a category").
|
||||
addOptions([
|
||||
{ label: "Products", value: "products" },
|
||||
{ label: "Community", value: "community" },
|
||||
{ label: "Company", value: "company" },
|
||||
]);
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal component rows
|
||||
modal.addComponents(
|
||||
new ActionRowBuilder<TextInputBuilder>().addComponents(contentInput),
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- discord.js types don't yet reflect select menus in modals, but they're supported at the API level
|
||||
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
|
||||
categorySelect,
|
||||
) as unknown as ActionRowBuilder<TextInputBuilder>,
|
||||
);
|
||||
|
||||
await interaction.showModal(modal);
|
||||
} catch (error) {
|
||||
const id = await errorHandler(error, "announcement command");
|
||||
await interaction.reply({
|
||||
content: `An error occurred whilst processing your request. Error ID: \`${id}\``,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user