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:
2026-03-12 23:01:19 -07:00
committed by Naomi Carrigan
parent ab1c41224d
commit 2991a56147
7 changed files with 258 additions and 3 deletions
+72
View File
@@ -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,
});
}
};