From 5f4e28f7bc58eb13e38b609beb6a9e1f80d70ab1 Mon Sep 17 00:00:00 2001 From: amy Date: Wed, 30 Apr 2025 23:10:04 +0330 Subject: [PATCH] randnum --- .idea/prettier.xml | 7 +++++++ src/commands/randnum.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .idea/prettier.xml create mode 100644 src/commands/randnum.ts diff --git a/.idea/prettier.xml b/.idea/prettier.xml new file mode 100644 index 0000000..0c83ac4 --- /dev/null +++ b/.idea/prettier.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/commands/randnum.ts b/src/commands/randnum.ts new file mode 100644 index 0000000..88a5ae6 --- /dev/null +++ b/src/commands/randnum.ts @@ -0,0 +1,41 @@ +import {Command} from "../command.ts"; +import { + ApplicationIntegrationType, + ChatInputCommandInteraction, + InteractionContextType, + SlashCommandBuilder +} from "discord.js"; +import { type Config } from "../config.ts"; + +export default class PingCommand extends Command { + async run(interaction: ChatInputCommandInteraction, config: Config) { + const upperbound = interaction.options.getInteger("upperbound")!; + const comment = interaction.options.getString("comment"); + + if (comment === null){ + await interaction.reply({ + content: "random number is: " + `${Math.floor(Math.random() * upperbound)}`, + }); + return + } + await interaction.reply({ + content: `chances of ${comment} out of ${upperbound} is ${Math.floor(Math.random() * upperbound)}`, + }); + + } + + slashCommand = new SlashCommandBuilder() + .setName("randnum") + .setDescription("random number").setIntegrationTypes([ + ApplicationIntegrationType.UserInstall + ]).addIntegerOption(option => { + return option.setName("upperbound").setRequired(true).setDescription("idk nea told me") + }).addStringOption(option => { + return option.setName("comment").setRequired(false).setDescription("comment") + }) + .setContexts([ + InteractionContextType.BotDM, + InteractionContextType.Guild, + InteractionContextType.PrivateChannel + ]); +}