diff --git a/commands/games/coin-flip.js b/commands/games/coin-flip.js new file mode 100644 index 0000000..4d16289 --- /dev/null +++ b/commands/games/coin-flip.js @@ -0,0 +1,12 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("coinflip") + .setDescription("Flip a coin!"), + + async execute(interaction) { + const result = Math.random() < 0.5 ? "Heads" : "Tails"; + await interaction.reply(`🪙 It's ${result}!`); + }, +}; diff --git a/commands/games/dice-roll.js b/commands/games/dice-roll.js new file mode 100644 index 0000000..c161a1d --- /dev/null +++ b/commands/games/dice-roll.js @@ -0,0 +1,23 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("roll") + .setDescription("Roll a dice!") + .addIntegerOption((option) => + option + .setName("sides") + .setDescription("Number of sides on the dice") + .setRequired(false) + .setMinValue(2) + .setMaxValue(100) + ), + + async execute(interaction) { + const sides = interaction.options.getInteger("sides") || 6; + const result = Math.floor(Math.random() * sides) + 1; + await interaction.reply( + `🎲 You rolled a ${result} on a ${sides}-sided dice!` + ); + }, +}; diff --git a/commands/games/rock-paper-scissors.js b/commands/games/rock-paper-scissors.js new file mode 100644 index 0000000..04b9c78 --- /dev/null +++ b/commands/games/rock-paper-scissors.js @@ -0,0 +1,41 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("rps") + .setDescription("Play Rock Paper Scissors!") + .addStringOption((option) => + option + .setName("choice") + .setDescription("Choose rock, paper, or scissors") + .setRequired(true) + .addChoices( + { name: "Rock", value: "rock" }, + { name: "Paper", value: "paper" }, + { name: "Scissors", value: "scissors" } + ) + ), + + async execute(interaction) { + const userChoice = interaction.options.getString("choice"); + const choices = ["rock", "paper", "scissors"]; + const botChoice = choices[Math.floor(Math.random() * choices.length)]; + + let result; + if (userChoice === botChoice) { + result = "It's a draw!"; + } else if ( + (userChoice === "rock" && botChoice === "scissors") || + (userChoice === "paper" && botChoice === "rock") || + (userChoice === "scissors" && botChoice === "paper") + ) { + result = "You win!"; + } else { + result = "You lose!"; + } + + await interaction.reply( + `You chose ${userChoice}. I chose ${botChoice}. ${result}` + ); + }, +}; diff --git a/index.js b/index.js index 87515df..5d59217 100644 --- a/index.js +++ b/index.js @@ -66,12 +66,13 @@ client.once("ready", async () => { // Register commands for all existing guilds const guilds = client.guilds.cache.map((guild) => guild.id); - // Seed the shop items - for (const guildId of guilds) { - await seedShopItems(guildId); - await seedSpyfallLocations(guildId); - await registerCommands(guildId); - } + await Promise.all( + guilds.map(async (guildId) => { + await seedShopItems(guildId); + await seedSpyfallLocations(guildId); + await registerCommands(guildId); + }) + ); // Set bot status and activity client.user.setPresence({