import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { weaponAutocomplete, getItem, getItemQuantity, formatItems } from '../lib/rpg/items'; import { Command } from '../types/index'; import { initHealth, dealDamage, BLOOD_ITEM, BLOOD_ID } from '../lib/rpg/pvp'; export default { data: new SlashCommandBuilder() .setName('attack') .setDescription('Attack someone using a weapon you have') .addStringOption(option => option .setName('weapon') .setAutocomplete(true) .setDescription('The weapon to use') .setRequired(true) ) .addUserOption(option => option .setName('user') .setRequired(true) .setDescription('Who to attack with the weapon') ) .setDMPermission(false), execute: async (interaction: CommandInteraction) => { if (!interaction.isChatInputCommand()) return; const member = interaction.member! as GuildMember; await initHealth(member.id); const weaponID = parseInt(interaction.options.getString('weapon', true)); const user = interaction.options.getUser('user', true); await interaction.deferReply({ephemeral: true}); const weapon = await getItem(weaponID); if (!weapon) return interaction.followUp('No such item exists!'); if (weapon.type !== 'weapon') return interaction.followUp('That is not a weapon!'); const dmg = weapon.maxStack; await dealDamage(user.id, dmg); const newHealth = await getItemQuantity(user.id, BLOOD_ID); await interaction.followUp(`You hit ${user} for ${BLOOD_ITEM.emoji} **${dmg}** damage! They are now at ${formatItems(BLOOD_ITEM, newHealth.quantity)}.`); }, autocomplete: weaponAutocomplete, } satisfies Command;