jillo-bot/src/commands/take.ts

42 lines
1.3 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 { changeLinkedCounterInteraction, linkedCounterAutocomplete } from '../lib/rpg/counter';
2023-11-21 20:17:15 +01:00
import { initHealth } from '../lib/rpg/pvp';
2023-11-16 11:33:11 +01:00
import { Command } from '../types/index';
2023-11-15 11:03:01 +01:00
2023-11-16 11:33:11 +01:00
export default {
2023-11-15 11:03:01 +01:00
data: new SlashCommandBuilder()
.setName('take')
.setDescription('Take an item from a counter')
.addStringOption(option =>
option
.setName('type')
.setAutocomplete(true)
.setDescription('The name of the counter')
.setRequired(true)
)
.addIntegerOption((option) =>
option
.setName('amount')
.setRequired(false)
.setDescription('Amount of items to take')
.setMinValue(1)
)
.setDMPermission(false),
2023-11-16 11:33:11 +01:00
execute: async (interaction: CommandInteraction) => {
2023-11-15 11:03:01 +01:00
if (!interaction.isChatInputCommand()) return;
2023-11-16 11:33:11 +01:00
const member = interaction.member! as GuildMember;
2023-11-15 11:03:01 +01:00
2023-11-21 20:17:15 +01:00
await initHealth(member.id);
2023-11-15 11:03:01 +01:00
const amount = Math.trunc(interaction.options.getInteger('amount') || 1);
const type = interaction.options.getString('type')!;
await interaction.deferReply({ephemeral: true});
changeLinkedCounterInteraction(interaction, member, -amount, type);
},
2023-11-22 14:45:55 +01:00
autocomplete: linkedCounterAutocomplete,
2023-11-16 11:33:11 +01:00
} satisfies Command;