### Installing Dressed Framework Source: https://github.com/inbestigator/dressed/blob/main/README.md Add Dressed as a project dependency using either the Bun package manager or Deno's JSR registry. ```bash bun add dressed ``` ```bash deno add jsr:@dressed/dressed ``` -------------------------------- ### Install Dressed and Dressed/Next with Bun Source: https://github.com/inbestigator/dressed/blob/main/packages/dressed-next/README.md Installs the necessary packages for using Dressed and @dressed/next in your project using the Bun package manager. ```bash bun add dressed @dressed/next ``` -------------------------------- ### Install Dressed using Bun Source: https://github.com/inbestigator/dressed/blob/main/www/content/home.md This command adds the Dressed package to your project using the Bun package manager, which is required to use the framework. ```bash bun add dressed ``` -------------------------------- ### Installing Dressed Dependency (Bun/Deno) Source: https://github.com/inbestigator/dressed/blob/main/packages/dressed/README.md This snippet shows how to add the Dressed framework to your project using either the Bun package manager or Deno's JSR registry. ```bash bun add dressed # or deno add jsr:@dressed/dressed ``` -------------------------------- ### Defining a Dressed Command (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/README.md Example of creating a simple 'ping' command using Dressed's CommandConfig and handling the interaction to reply with 'Pong!'. ```typescript // src/commands/ping.ts import type { CommandConfig, CommandInteraction } from "dressed"; export const config: CommandConfig = { description: "Returns pong" }; export default async function (interaction: CommandInteraction) { await interaction.reply({ content: "Pong!", ephemeral: true }); } ``` -------------------------------- ### Handling Component Interaction (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/components.md Provides an example of the required default export function for handling component interactions. This asynchronous function receives the ComponentInteraction object and an arguments object, allowing conditional logic based on interaction details and dynamic arguments. ```ts import type { ComponentInteraction } from "dressed"; export default async function ( interaction: ComponentInteraction, args: { answer: string }, ) { if (args.answer === correctAnswer) { await interaction.reply("Good job!"); } else { await interaction.reply("Nice try!"); } } ``` -------------------------------- ### Building and Running the Dressed Bot (Bun/Deno) Source: https://github.com/inbestigator/dressed/blob/main/packages/dressed/README.md These commands illustrate how to build the bot's code using the Dressed CLI tool and then execute the generated entry point file (bot.gen.ts) with either Bun or Deno. The build command includes flags for instance creation (-i) and command registration (-r). ```bash bun dressed build -ir bun bot.gen.ts # or deno -A jsr:@dressed/cmd build -ir deno -A bot.gen.ts ``` -------------------------------- ### Building and Running Dressed Bot Source: https://github.com/inbestigator/dressed/blob/main/README.md Commands to build the bot's boilerplate code and then execute the generated entry point, with options to include an instance creator (-i) and register commands (-r). ```bash bun dressed build -ir bun bot.gen.ts ``` ```bash deno -A jsr:@dressed/cmd build -ir deno -A bot.gen.ts ``` -------------------------------- ### Build and Run Dressed Bot with Bun Source: https://github.com/inbestigator/dressed/blob/main/www/content/home.md These bash commands build the Dressed bot project, including options for instance creation and command registration (-ir), and then execute the generated bot file. ```bash bun dressed build -ir bun bot.gen.ts ``` -------------------------------- ### Command File Structure (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/commands.md Illustrates the typical directory structure for commands in the Dressed project, showing how file names map to command names. ```text src └ commands ├ greet.ts // Will become /greet └ trivia.ts // Will become /trivia ``` -------------------------------- ### Component File Structure Mapping (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/components.md Illustrates the typical directory structure for components in Dressed, showing how file names within 'buttons', 'modals', and 'selects' directories determine the component IDs they handle, including support for dynamic arguments in file names. ```ts src └ components ├ buttons │ ├ increase.ts // Will handle for buttons with ID `increase` │ └ trivia_guess_[answer].ts // Will handle for buttons with ID `trivia_guess_(.+)` ├ modals │ └ suggestion.ts // Will handle for modals with ID `suggestion` └ selects └ rating.ts // Will handle for selectmenu submissions with ID `rating` ``` -------------------------------- ### Defining a Basic Discord Command (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/packages/dressed/README.md This TypeScript snippet demonstrates how to create a simple command handler for a Dressed bot. It defines the command configuration and an asynchronous function to handle the interaction, replying ephemerally. ```ts // src/commands/ping.ts import type { CommandConfig, CommandInteraction } from "dressed"; export const config: CommandConfig = { description: "Returns pong" }; export default async function (interaction: CommandInteraction) { await interaction.reply({ content: "Pong!", ephemeral: true }); } ``` -------------------------------- ### Create Next.js API Route Handler for Dressed Source: https://github.com/inbestigator/dressed/blob/main/packages/dressed-next/README.md Sets up a Next.js API route (`app/bot/route.ts`) to handle Discord interactions by importing the `createHandler` function from `@dressed/next` and passing generated command, component, and event handlers. ```typescript // app/bot/route.ts import createHandler from "@dressed/next"; import { commands, components, events } from "@/bot.gen"; export const POST = createHandler(commands, components, events); ``` -------------------------------- ### Handling Dynamic Component Arguments (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/components.md Demonstrates how a component handler function receives dynamic arguments parsed from the component's file name. The `args` object contains properties corresponding to the `[]` placeholders in the file name, allowing handlers to access specific values from the component ID. ```ts export default async function print(_, args: { value: string }) { console.log(value); } ``` -------------------------------- ### Defining Command Configuration in Dressed (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/commands/config.md This snippet demonstrates how to define the configuration object for a command in the 'dressed' project using TypeScript. It imports the necessary `CommandConfig` and `CommandOption` types and exports a `config` object specifying the command's description and required options, such as an 'animal' string option. ```typescript import { type CommandConfig, CommandOption } from "dressed"; export const config: CommandConfig = { description: "Send a random adorable animal photo", options: [ CommandOption({ name: "animal", description: "The type of animal", type: "String", required: true, }), ], }; ``` -------------------------------- ### Implement Ping Command in TypeScript Source: https://github.com/inbestigator/dressed/blob/main/www/content/home.md This TypeScript snippet demonstrates how to define a basic command configuration and an asynchronous handler function using Dressed types, replying with an ephemeral 'Pong!' message. ```typescript // src/commands/ping.ts import type { CommandConfig, CommandInteraction } from "dressed"; export const config: CommandConfig = { description: "Returns pong" }; export default async function (interaction: CommandInteraction) { await interaction.reply({ content: "Pong!", ephemeral: true }); } ``` -------------------------------- ### Reply Base Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Sends an immediate response to the interaction. Requires the `data` parameter which contains the message content or options. ```TypeScript await interaction.reply({ content: "Hello!", ephemeral: true }); ``` -------------------------------- ### Show Modal Base Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Responds to the interaction by displaying a modal dialog to the user. This method is not available for modal submission interactions. Requires the `data` parameter containing the modal structure, including title, custom ID, and components. ```TypeScript await interaction.showModal({ title: "Example Modal", custom_id: "modal_id", components: [...], }); ``` -------------------------------- ### Follow Up Base Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Sends an additional message related to the interaction after the initial response. Requires the `data` parameter containing the follow-up message content or options. ```TypeScript await interaction.followUp({ content: "Another message!", ephemeral: true, }); ``` -------------------------------- ### Default Command Execution Function (TypeScript) Source: https://github.com/inbestigator/dressed/blob/main/www/content/commands.md Defines the required default export function for handling command interactions, demonstrating a simple reply using the CommandInteraction type. ```TypeScript import type { CommandInteraction } from "dressed"; export default async function (interaction: CommandInteraction) { await interaction.reply("Hi there!"); } ``` -------------------------------- ### getOption Command Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Retrieves the value of a specific option from a command interaction. Takes the option `name` as a string and an optional `required` boolean; if `required` is true and the option is missing, an error is thrown. ```TypeScript const user = interaction.getOption("user", true).user(); ``` -------------------------------- ### Defer Reply Base Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Acknowledges the interaction, showing a "thinking..." indicator to the user. Allows for editing or responding later. Accepts an optional `data` parameter for options like making the deferral ephemeral. ```TypeScript await interaction.deferReply({ ephemeral: true }); ``` -------------------------------- ### Edit Reply Base Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Edits the initial response that was sent to the interaction. Requires the `data` parameter containing the updated message content or options. ```TypeScript await interaction.editReply("Updated message content"); ``` -------------------------------- ### update Message Component Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Edits the original message that contained the message component which triggered the interaction. Requires the `data` parameter containing the new content or message options. ```TypeScript await interaction.update("Updated content"); ``` -------------------------------- ### getField Modal Submit Interaction Source: https://github.com/inbestigator/dressed/blob/main/www/content/interactions.md Retrieves the value of a specific field from a modal submission interaction. Takes the field `name` as a string and an optional `required` boolean; if `required` is true and the field is missing, an error is thrown. ```TypeScript const fieldValue = interaction.getField("input_name", true); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.