const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('rps') .setDescription("Play a game of rock paper scissor with someone.") .addUserOption(option => option .setName('user') .setDescription("The user whom you wanna play with.") .setRequired(true)) .setDMPermission(false), async execute(interaction) { let opponent = interaction.options.getUser('user'); if (opponent.id == interaction.user.id) return await interaction.reply({ content: "<:Smike_x_mark:1058994007449014293> You cannot play with yourself!", ephemeral: true }); if (opponent.bot) return await interaction.reply({ content: "<:Smike_x_mark:1058994007449014293> You cannot play with bots!", ephemeral: true }); let tie = new EmbedBuilder() .setTitle('Tie') .setFooter({ text: "Rock paper scissor game." }) .setTimestamp() .setColor('NotQuiteBlack'); let won = new EmbedBuilder() .setFooter({ text: "Rock paper scissor game." }) .setTimestamp(); let playerClicks = 0; let opponentClicks = 0; let opponentMove = ''; let rps = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel('Rock') .setEmoji('🪨') .setCustomId('rock') .setStyle(ButtonStyle.Danger), new ButtonBuilder() .setLabel('Paper') .setEmoji('📄') .setCustomId('paper') .setStyle(ButtonStyle.Success), new ButtonBuilder() .setLabel('Scissor') .setEmoji('✂️') .setCustomId('scissor') .setStyle(ButtonStyle.Primary)); let rpsOpponent = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel('Rock') .setEmoji('🪨') .setCustomId('rock-2') .setStyle(ButtonStyle.Danger), new ButtonBuilder() .setLabel('Paper') .setEmoji('📄') .setCustomId('paper-2') .setStyle(ButtonStyle.Success), new ButtonBuilder() .setLabel('Scissor') .setEmoji('✂️') .setCustomId('scissor-2') .setStyle(ButtonStyle.Primary)); let rpsDisabled = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel('Rock') .setEmoji('🪨') .setCustomId('rock-disabled') .setStyle(ButtonStyle.Danger) .setDisabled(true), new ButtonBuilder() .setLabel('Paper') .setEmoji('📄') .setCustomId('paper-disabled') .setStyle(ButtonStyle.Success) .setDisabled(true), new ButtonBuilder() .setLabel('Scissor') .setEmoji('✂️') .setCustomId('scissor-disabled') .setStyle(ButtonStyle.Primary) .setDisabled(true)); let reply = await interaction.reply({ content: `${opponent}\nChoose your move!`, components: [rpsOpponent] }); let collector = await reply.createMessageComponentCollector({ time: 30000 }); collector.on('collect', async (i) => { if (i.customId === 'rock-2') { await i.deferUpdate(); if (i.user.id !== opponent.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else { opponentClicks = 1; opponentMove = 'Rock'; collector.time += 30000; await i.followUp({ content: "You chose 🪨", ephemeral: true }); await i.editReply({ content: `${interaction.user}\nChoose your move!`, components: [rps] }); } } else if (i.customId === 'paper-2') { await i.deferUpdate(); if (i.user.id !== opponent.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else { opponentClicks = 1; opponentMove = 'Paper'; collector.time += 30000; await i.followUp({ content: "You chose 📄", ephemeral: true }); await i.editReply({ content: `${interaction.user}\nChoose your move!`, components: [rps] }); } } else if (i.customId === 'scissor-2') { await i.deferUpdate(); if (i.user.id !== opponent.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else { opponentClicks = 1; opponentMove = 'Scissor'; collector.time += 30000; await i.followUp({ content: "You chose ✂️", ephemeral: true }); await i.editReply({ content: `${interaction.user}\nChoose your move!`, components: [rps] }); } } else if (i.customId === 'rock' && opponentMove == 'Rock') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [tie.setDescription("The game tied! Both of you chose 🪨")], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'paper' && opponentMove == 'Paper') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [tie.setDescription("The game tied! Both of you chose 📄")], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'scissor' && opponentMove == 'Scissor') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [tie.setDescription("The game tied! Both of you chose ✂️")], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'rock' && opponentMove == 'Paper') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${opponent.username} won!`).setDescription(`**${interaction.user.username}** chose 🪨\n**${opponent.username}** chose 📄`).setColor('#ff0000')], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'rock' && opponentMove == 'Scissor') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${interaction.user.username} won!`).setDescription(`**${interaction.user.username}** chose 🪨\n**${opponent.username}** chose ✂️`).setColor('#00ff00')], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'paper' && opponentMove == 'Scissor') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${opponent.username} won!`).setDescription(`**${interaction.user.username}** chose 📄\n**${opponent.username}** chose ✂️`).setColor('#ff0000')], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'scissor' && opponentMove == 'Rock') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${opponent.username} won!`).setDescription(`**${interaction.user.username}** chose ✂️\n**${opponent.username}** chose 🪨`).setColor('#ff0000')], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'scissor' && opponentMove == 'Paper') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${interaction.user.username} won!`).setDescription(`**${interaction.user.username}** chose ✂️\n**${opponent.username}** chose 📄`).setColor('#00ff00')], components: [rpsDisabled] }); playerClicks = 1; } else if (i.customId === 'paper' && opponentMove == 'Rock') { await i.deferUpdate(); if (i.user.id !== interaction.user.id) return await i.followUp({ content: "<:Smike_x_mark:1058994007449014293> You cannot use these buttons!", ephemeral: true }); else await i.editReply({ content: '', embeds: [won.setTitle(`${interaction.user.username} won!`).setDescription(`**${interaction.user.username}** chose 📄\n**${opponent.username}** chose 🪨`).setColor('#00ff00')], components: [rpsDisabled] }); playerClicks = 1; } }); collector.on('end', async () => { if (opponentClicks == 0) return await interaction.editReply({ content: `I guess **${opponent.username}** is not interested in playing!`, embeds: [], components: [rpsDisabled] }).catch((error) => { return; }); else if (playerClicks == 0) return await interaction.editReply({ content: "I guess you don't wanna play!", embeds: [], components: [rpsDisabled] }).catch((error) => { return; }); else return; }); }, };