jillo-bot/src/commands/decrease.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-16 11:33:11 +01:00
import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js';
2023-11-15 11:57:20 +01:00
import { changeCounterInteraction, counterAutocomplete } from '../lib/rpg/counter';
2023-11-16 11:33:11 +01:00
import { Command } from '../types/index';
2022-07-19 21:39:34 +02:00
2023-11-16 11:33:11 +01:00
export default {
2022-07-19 21:39:34 +02:00
data: new SlashCommandBuilder()
.setName('decrease')
2023-11-11 00:01:38 +01:00
.setDescription('Decrease a counter')
.addStringOption(option =>
option
.setName('type')
.setAutocomplete(true)
.setDescription('The name of the counter')
.setRequired(true)
)
.addIntegerOption((option) =>
2022-07-19 21:39:34 +02:00
option
.setName('amount')
.setRequired(false)
.setDescription('Amount to decrease the counter by')
.setMinValue(1)
2023-11-11 00:01:38 +01:00
)
.setDMPermission(false),
2023-11-16 11:33:11 +01:00
execute: async (interaction: CommandInteraction) => {
if (!interaction.isChatInputCommand()) return;
2023-11-16 11:33:11 +01:00
const member = interaction.member! as GuildMember;
2022-10-17 20:04:30 +02:00
const amount = Math.trunc(interaction.options.getInteger('amount') || 1);
2023-11-11 00:01:38 +01:00
const type = interaction.options.getString('type')!;
await interaction.deferReply({ephemeral: true});
changeCounterInteraction(interaction, member, -amount, type);
},
2023-11-22 14:45:55 +01:00
autocomplete: counterAutocomplete,
2023-11-16 11:33:11 +01:00
} satisfies Command;