const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ApplicationCommandOptionType } = require('discord.js'); const config = require('../../config.json') const healthBar = config.healthStart+config.healthMiddle+config.healthMiddle+config.healthEnd let healthBot = 200 let healthPlayer = 200 module.exports.run = async function (client, inter) { //embeds const embed = new EmbedBuilder() .setColor("Blurple") .setTitle("Battle Me") .setDescription("Are you sure you want to start a battle?") const matchEmbed = new EmbedBuilder() .setColor("Blurple") .setTitle(`${client.user.username} vs ${inter.user.username}`) .setDescription("You have 30 seconds to choose a move.") .addFields( { name: `${client.user.username}`, value: healthBar+'\n'+healthBot, inline: true }, { name: `${inter.user.username}`, value: healthBar+'\n'+healthPlayer, inline: true } ) const cancelEmbed = new EmbedBuilder() .setColor("Red") .setTitle("Battle Cancelled") .setDescription("You cancelled the battle.") const surrenderEmbed = new EmbedBuilder() .setColor("Red") .setDescription("You surrendered the match.") //buttons const start = new ButtonBuilder() .setCustomId('start') .setLabel('Start') .setStyle(ButtonStyle.Success); const cancel = new ButtonBuilder() .setCustomId('cancel') .setLabel('Cancel') .setStyle(ButtonStyle.Secondary); const punchButton = new ButtonBuilder() .setCustomId('punch') .setLabel('Punch') .setStyle(ButtonStyle.Secondary) .setEmoji(config.punch) const kickButton = new ButtonBuilder() .setCustomId('kick') .setLabel('Kick') .setStyle(ButtonStyle.Secondary) .setEmoji(config.kick) const surrender = new ButtonBuilder() .setCustomId('surrender') .setLabel('Surrender') .setStyle(ButtonStyle.Danger) //action rows const row = new ActionRowBuilder() .addComponents(start, cancel); const attacks = new ActionRowBuilder() .addComponents(punchButton, kickButton, surrender); const response = await inter.reply({ embeds: [embed], components: [row], }); const collectorFilter = i => i.user.id === inter.user.id; try { const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 }); if (confirmation.customId === 'start') { await confirmation.update({ embeds: [matchEmbed], components: [attacks] }) } else if (confirmation.customId === 'cancel') { await confirmation.update({ embeds: [cancelEmbed], components: [] }); } else if (confirmation.customId === 'punch') { await confirmation.update({ content: 'You punched!', embeds: [], components: [attacks] }); } else if (confirmation.customId === 'kick') { await confirmation.update({ content: 'You kicked!', embeds: [], components: [attacks] }); } else if (confirmation.customId === 'surrender') { await confirmation.update({ embeds: [surrenderEmbed], components: [] }); } } catch (e) { await inter.editReply({ content: 'No response, cancelling match', components: [], embeds: [] }); } /*const collectorFilter2 = j => j.user.id === inter.user.id; try { const confirmation = await matchResponse.awaitMessageComponent({ filter: collectorFilter2, time: 30_000 }); if (confirmation.customId === 'punch') { await confirmation.update({ embeds: [surrenderEmbed], components: [attacks] }); } else if (confirmation.customId === 'kick') { await confirmation.update({ embeds: [surrenderEmbed], components: [attacks] }); } else if (confirmation.customId === 'surrender') { await confirmation.update({ embeds: [surrenderEmbed], components: [] }); } } catch (e) { await confirmation.update({ content: 'You did not choose a move, match is over', components: [], embeds: [] }); }*/ } module.exports.help = { name: 'battlebot', description: "Have a friendly battle with me!", options: [ { name: 'battlemode', description: 'Choose a battle mode', type: ApplicationCommandOptionType.String, required: false } ] }