Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Subcommand } from '@sapphire/plugin-subcommands';
- import { ActionRowBuilder, ModalActionRowComponentBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
- import CustomEmbed, { CustomEmbedType } from '../lib/CustomEmbed.js';
- /**
- * Adds usable quotes.
- */
- export class QuotesSubcommandGroup extends Subcommand {
- /**
- * The modals used within this command.
- */
- private static readonly _modals = {
- add: new ModalBuilder() //
- .setTitle('Adding new quotes.')
- .setCustomId('add_quotes')
- .setComponents([
- new ActionRowBuilder<ModalActionRowComponentBuilder>() //
- .setComponents([
- new TextInputBuilder() //
- .setLabel('A comma separated list of quotes to add.')
- .setRequired(true)
- .setStyle(TextInputStyle.Paragraph)
- .setMinLength(1)
- .setCustomId('quote')
- ])
- ])
- };
- public constructor(context: Subcommand.LoaderContext, options: Subcommand.Options) {
- super(context, {
- ...options,
- name: 'quotes',
- subcommands: [
- {
- name: 'add',
- chatInputRun: 'chatInputAdd'
- },
- {
- name: 'remove',
- chatInputRun: 'chatInputRemove'
- }
- ]
- });
- }
- /**
- * The modals used within this command.
- */
- public static get modals() {
- return this._modals;
- }
- /**
- * Registers this slash command.
- *
- * @param registry - The {@link Command.Registry} instance associated with this command.
- */
- public override registerApplicationCommands(registry: Subcommand.Registry) {
- registry.registerChatInputCommand(
- (builder) =>
- builder
- .setName('quotes') //
- .setDescription('Manages the list of quotes.')
- .setDefaultMemberPermissions('0')
- .addSubcommand((subCommand) => {
- return subCommand //
- .setName('add')
- .setDescription('Add quotes to the list.');
- })
- .addSubcommand((subCommand) => {
- return subCommand //
- .setName('remove')
- .setDescription('Remove a quote from the list.')
- .addStringOption((option) => {
- return option //
- .setName('quote')
- .setDescription('The quote to remove.')
- .setMinLength(1)
- .setRequired(true);
- });
- }),
- {
- idHints: ['1217906420926644305'],
- guildIds: this.container.environment.GUILD_IDS.split(',')
- }
- /**
- * Don't forget to add the command's id to `idHints` when the command is registered.
- *
- * ```
- * {
- * idHints: [...]
- * }
- * ```
- */
- );
- }
- /**
- * Handles the `/quotes add` subcommand.
- *
- * @param interaction - The {@link Command.ChatInputCommandInteraction} object received.
- */
- public async chatInputAdd(interaction: Subcommand.ChatInputCommandInteraction) {
- console.log(interaction.commandId);
- await interaction.showModal(QuotesSubcommandGroup._modals.add);
- }
- /**
- * Handles the `/quotes remove <quote>` subcommand.
- *
- * @param interaction - The {@link Command.ChatInputCommandInteraction} object received.
- */
- public async chatInputRemove(interaction: Subcommand.ChatInputCommandInteraction) {
- await interaction.deferReply({
- ephemeral: true
- });
- const quoteToRemove = interaction.options.getString('quote', true);
- const removedQuote = await this.container.database.models.quotes.removeQuote(quoteToRemove);
- const embed = //
- new CustomEmbed(removedQuote ? CustomEmbedType.Success : CustomEmbedType.Error) //
- .setDescription(removedQuote ? 'The specified quote was removed successfully.' : 'Could not find the specified quote.');
- await interaction.editReply({
- embeds: [embed]
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement