import { CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { isSubscribed, subscribe, timeAnnouncements, unsubscribe } from '../lib/subscriptions'; import { Command } from '../types/index'; export default { data: new SlashCommandBuilder() .setName('subscribe') .setDescription('[ADMIN] Subscribe/unsubscribe to a time announcement') .addStringOption(option => option .setName('type') .setChoices(...Object.keys(timeAnnouncements).map(l => ({name: l, value: l}))) .setDescription('The name of the time announcement') .setRequired(true) ) .setDefaultMemberPermissions('0'), execute: async (interaction: CommandInteraction) => { if (!interaction.isChatInputCommand()) return; await interaction.deferReply({ephemeral: true}); const announcementType = interaction.options.getString('type', true); const channel = interaction.channelId; if (await isSubscribed(announcementType, channel)) { await unsubscribe(announcementType, channel); await interaction.followUp({ content: `<#${interaction.channelId}> has been unsubscribed from \`${announcementType}\`` }); } else { await subscribe(announcementType, interaction.guildId || undefined, channel); await interaction.followUp({ content: `<#${interaction.channelId}> has been subscribed to \`${announcementType}\`` }); } } } satisfies Command;