-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Command for Char / Word Count
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { CacheType, Interaction } from "discord.js"; | ||
|
||
const COUNT = "COUNT"; | ||
|
||
export const charCommand = { | ||
name: "text", | ||
description: "Tools to work with characters / words", | ||
options: [ | ||
{ | ||
name: "operation", | ||
description: "The type of operation to perform", | ||
required: true, | ||
type: 3, | ||
choices: [{ name: "Count", value: COUNT }], | ||
}, | ||
{ | ||
name: "text", | ||
description: "The text to operate on", | ||
required: true, | ||
type: 3, | ||
}, | ||
], | ||
|
||
execute: async (interaction: Interaction<CacheType>) => { | ||
if (!interaction.isCommand()) return; | ||
|
||
const { options } = interaction; | ||
|
||
const operationOption = options.get("operation"); | ||
if (operationOption) { | ||
const operation = operationOption.value as string; | ||
|
||
switch (operation) { | ||
case COUNT: { | ||
const text = options.get("text")?.value as string; | ||
const charCount = text.length; | ||
const wordCount = text.split(" ").length; | ||
|
||
await interaction.reply( | ||
`Character count: ${charCount}\nWord count: ${wordCount}` | ||
); | ||
break; | ||
} | ||
} | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters