add coin flip, dice roll and rock paper scissors commands, and fix registerting commands for guild using promise

This commit is contained in:
Ayden Jahola 2024-10-28 23:27:17 +00:00
parent 49be1ec673
commit 7e74d3e4e6
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742
4 changed files with 83 additions and 6 deletions

View file

@ -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}!`);
},
};

View file

@ -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!`
);
},
};

View file

@ -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}`
);
},
};

View file

@ -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({