mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-23 09:15:56 +00:00
add coin flip, dice roll and rock paper scissors commands, and fix registerting commands for guild using promise
This commit is contained in:
parent
49be1ec673
commit
7e74d3e4e6
4 changed files with 83 additions and 6 deletions
12
commands/games/coin-flip.js
Normal file
12
commands/games/coin-flip.js
Normal 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}!`);
|
||||
},
|
||||
};
|
23
commands/games/dice-roll.js
Normal file
23
commands/games/dice-roll.js
Normal 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!`
|
||||
);
|
||||
},
|
||||
};
|
41
commands/games/rock-paper-scissors.js
Normal file
41
commands/games/rock-paper-scissors.js
Normal 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}`
|
||||
);
|
||||
},
|
||||
};
|
7
index.js
7
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 Promise.all(
|
||||
guilds.map(async (guildId) => {
|
||||
await seedShopItems(guildId);
|
||||
await seedSpyfallLocations(guildId);
|
||||
await registerCommands(guildId);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Set bot status and activity
|
||||
client.user.setPresence({
|
||||
|
|
Loading…
Reference in a new issue