From 8e60943ba772e40f7ba93e5401a0188b0f1fb5ed Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 4 Apr 2023 17:15:56 -0500 Subject: [PATCH] Add countChars function --- commands/countChars.ts | 20 +++++++++++++++++--- deploy-commands.js | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/commands/countChars.ts b/commands/countChars.ts index de2847d..e4a0bd2 100644 --- a/commands/countChars.ts +++ b/commands/countChars.ts @@ -7,10 +7,24 @@ module.exports = { .addStringOption( option => option.setName('string') .setDescription("String to count characters in") - .setRequired(true) - ), + .setRequired(false) + ) + .addStringOption( option => + option.setName('messageid') + .setDescription("Message ID of message to count characters in") + .setRequired(false) + ), async execute(interaction) { - var inputString = interaction.options.getString('string'); + var inputString; + + if (interaction.options.getString('string') !== null) { + inputString = interaction.options.getString('string'); + } else if (interaction.options.getString('messageid') !== null) { + var messageId = interaction.options.getString('messageid'); + const messagefromId = await client.channels.cache.get(interaction.channel.id).messages.fetch(messageId); + inputString = messagefromId.content; + } + await interaction.reply("Input: `" + inputString + "`\n" + "Output: " + codeBlock("", countChars(inputString))); console.log("User " + interaction.user.tag + " ran /count_chars"); }, diff --git a/deploy-commands.js b/deploy-commands.js index a7da7b4..079528f 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -1,4 +1,6 @@ const { REST, Routes } = require('discord.js'); +//var guildId = process.argv.slice(1).toString(); +//guildId = require('./key.json'); const { clientId, guildId, token } = require('./key.json'); const fs = require('node:fs'); const path = require('node:path');