### Install @discordx/music Source: https://discordx.js.org/api/music Install the library using npm or yarn. Ensure Node.js v16.6.0 or newer is installed, along with discord.js and @discordjs/voice. ```bash npm install @discordx/music yarn add @discordx/music ``` -------------------------------- ### Install @discordx/music Source: https://discordx.js.org/docs/music Install the discordx music library using npm or yarn. Ensure discord.js and @discordjs/voice are installed first. ```bash npm install @discordx/music yarn add @discordx/music ``` -------------------------------- ### Install YTDL Player Plugin Source: https://discordx.js.org/docs/plugin-ytdl-player Install the plugin using npm. ```bash npm install @discordx/plugin-ytdl-player ``` -------------------------------- ### Install @discordx/lava-player Source: https://discordx.js.org/api/lava-player/index.html Install the library using npm or yarn. Ensure you have Node.js version 16.6.0 or newer. ```bash npm install @discordx/lava-player yarn add @discordx/lava-player ``` -------------------------------- ### Install @discordx/lava-queue Source: https://discordx.js.org/api/lava-queue/index.html Install the library using npm or yarn. Version 16.6.0 or newer of Node.js is required. ```bash npm install @discordx/lava-queue yarn add @discordx/lava-queue ``` -------------------------------- ### Install @discordx/importer Source: https://discordx.js.org/docs/importer Install the library using npm or yarn. Node.js version 16.6.0 or newer is required. ```bash npm install @discordx/importer yarn add @discordx/importer ``` -------------------------------- ### Quick Example of @discordx/music Usage Source: https://discordx.js.org/api/music This example demonstrates how to initialize QueueNode and TrackQueue, join a voice channel, and add a track to the queue. Ensure 'client', 'guildId', 'channelId', and 'VIDEO_URL' are properly defined. ```typescript // Create a queue node const queueNode = new QueueNode(client); // Create a track queue for guild const trackQueue = new TrackQueue({ client: client, guildId: guildId, queueNode: queueNode, }); // Join voice channel queue.join({ channelId: channelId, guildId: guildId, }); // Add and play track queue.addTrack({ url: "VIDEO_URL", }); ``` -------------------------------- ### Install Discord.js Bot Project Source: https://discordx.js.org/docs/create-discordx Use this command to quickly set up a new Discord bot project with discordx. It initializes the project structure and installs necessary dependencies. ```bash npx create-discordx ``` -------------------------------- ### Quick Example: Music Bot Functionality Source: https://discordx.js.org/api/music/index.html This example demonstrates how to initialize QueueNode and TrackQueue for a specific guild, join a voice channel, and add a track to play. Ensure 'client', 'guildId', and 'channelId' are properly defined. ```typescript // Create a queue node const queueNode = new QueueNode(client); // Create a track queue for guild const trackQueue = new TrackQueue({ client: client, guildId: guildId, queueNode: queueNode, }); // Join voice channel queue.join({ channelId: channelId, guildId: guildId, }); // Add and play track queue.addTrack({ url: "VIDEO_URL", }); ``` -------------------------------- ### Install discordx Source: https://discordx.js.org/api/discordx/index.html Install discordx using npm or yarn. Node.js version 16.6.0 or newer is required. ```bash npm install discordx yarn add discordx ``` -------------------------------- ### Install Discordx and Discord.js with Bun Source: https://discordx.js.org/docs/discordx/getting-started Install discordx and discord.js packages using Bun. These are the core libraries for building your bot. ```bash bun add discordx discord.js ``` -------------------------------- ### Install @discordx/music Source: https://discordx.js.org/api/music/index.html Install the library using npm or yarn. Ensure Node.js version 16.6.0 or newer is used, along with discord.js and @discordjs/voice. ```bash npm install @discordx/music ``` ```bash yarn add @discordx/music ``` -------------------------------- ### Install @discordx/utilities Source: https://discordx.js.org/api/utilities/index.html Install the @discordx/utilities package using npm or yarn. Node.js version 16.6.0 or newer is required. ```bash npm install @discordx/utilities yarn add @discordx/utilities ``` -------------------------------- ### Install @discordx/lava-player Source: https://discordx.js.org/docs/lava-player Install the library using npm or yarn. Ensure Node.js version 16.6.0 or newer is used. Lavalink must be running. ```bash npm install @discordx/lava-player yarn add @discordx/lava-player ``` -------------------------------- ### Setup Autocompletion with @SlashChoice Source: https://discordx.js.org/docs/discordx/decorators/command/slash-choice Demonstrates how to use the @SlashChoice decorator on command parameters to enable autocompletion for string and number options. It shows examples with string choices, number choices, and using enums/objects for choices. ```APIDOC ## Setup autocompletion You just decorate your parameter with one or multiple @SlashChoice ! ```typescript @Discord() class Example { @Slash({ description: "I am" }) iam( @SlashChoice({ name: "Human", value: "human" }) @SlashChoice({ name: "Astronaut", value: "astronaut" }) @SlashChoice({ name: "Dev", value: "dev" }) @SlashOption({ description: "What are you?", name: "what", required: true, type: ApplicationCommandOptionType.String, }) what: string, @SlashChoice(10, 20, 30) @SlashOption({ description: "fuel", name: "fuel", required: true, type: ApplicationCommandOptionType.Number, }) fuel: number, @SlashChoice("Patrol", "Diesel") @SlashOption({ description: "type", name: "type", required: true, type: ApplicationCommandOptionType.String, }) type: number, interaction: CommandInteraction, ) { interaction.reply(`what: ${what}, fuel: ${fuel}, type: ${type}`); } } ``` ## Use object or enum to define all the choices at once ```typescript enum TextChoices { // WhatDiscordShows = value Hello = "Hello", "Good Bye" = "Good Bye", } @Discord() class Example { @Slash({ description: "hello" }) hello( @SlashChoice( { name: TextChoices[TextChoices.Hello], value: TextChoices.Hello, }, { name: TextChoices[TextChoices["Good Bye"]], value: TextChoices["Good Bye"], }, ) @SlashChoice({ name: "How are you", value: "hay" }) @SlashOption({ description: "text", name: "text", required: true, type: ApplicationCommandOptionType.String, }) text: string, interaction: CommandInteraction, ) { interaction.reply(text); } } ``` ``` -------------------------------- ### Install Discordx and Discord.js with npm Source: https://discordx.js.org/docs/discordx/getting-started Install discordx and discord.js packages using npm. These are the core libraries for building your bot. ```bash npm install discordx discord.js ``` -------------------------------- ### Install discordx/di Source: https://discordx.js.org/docs/di Install the discordx/di package using npm or yarn. Requires Node.js version 16.6.0 or newer. ```bash npm install @discordx/di yarn add @discordx/di ``` -------------------------------- ### Install Discordx and Discord.js with pnpm Source: https://discordx.js.org/docs/discordx/getting-started Install discordx and discord.js packages using pnpm. These are the core libraries for building your bot. ```bash pnpm add discordx discord.js ``` -------------------------------- ### Install Discordx and Discord.js with Yarn Source: https://discordx.js.org/docs/discordx/getting-started Install discordx and discord.js packages using Yarn. These are the core libraries for building your bot. ```bash yarn add discordx discord.js ``` -------------------------------- ### Install @discordx/di Source: https://discordx.js.org/api/di Install the @discordx/di package using npm or yarn. Requires Node.js version 16.6.0 or newer. ```bash npm install @discordx/di yarn add @discordx/di ``` -------------------------------- ### Install tsx with Bun Source: https://discordx.js.org/docs/discordx/basics/debugging Install tsx as a dev dependency using Bun. This is required for debugging. ```bash bun add --dev tsx ``` -------------------------------- ### Quick Music Bot Example Source: https://discordx.js.org/docs/music Demonstrates how to create a QueueNode, a TrackQueue for a specific guild, join a voice channel, and add a track to play. ```typescript // Create a queue node const queueNode = new QueueNode(client); // Create a track queue for guild const trackQueue = new TrackQueue({ client: client, guildId: guildId, queueNode: queueNode, }); // Join voice channel queue.join({ channelId: channelId, guildId: guildId, }); // Add and play track queue.addTrack({ url: "VIDEO_URL", }); ``` -------------------------------- ### Install @discordx/pagination Source: https://discordx.js.org/api/pagination/index.html Install the @discordx/pagination package using npm or yarn. Node.js version 16.6.0 or newer is required. ```bash npm install @discordx/pagination yarn add @discordx/pagination ``` -------------------------------- ### Using @Bot Decorator with Multiple Bots Source: https://discordx.js.org/docs/discordx/decorators/general/bot This example demonstrates how to use the @Bot decorator to associate commands and events with specific bot instances. It shows the setup for two bots, 'alex' and 'zoe', and how to log them in after building the application. ```typescript @Discord() @Bot("alex", "zoe") // Define which bot can run the following commands or events class Example { @SimpleCommand() hello(command: SimpleCommandMessage) { command.message.reply(`👋 ${message.member}`); } } const alex = new Client({ botId: "alex", // define botId }); const zoe = new Client({ botId: "zoe", // define botId }); // We will now build our application to load all the commands/events for both bots. MetadataStorage.instance.build().then(() => { // Now that the app is ready, we can login to both bots alex.login("alex token"); zoe.login("zoe token"); }); ``` -------------------------------- ### login Source: https://discordx.js.org/api/discordx/classes/Client.html Starts the bot by logging in with a token. ```APIDOC ## login ### Description Start bot ### Method `login(token: string): Promise` ### Parameters #### Path Parameters - **token** (string) - Required - The bot token. ``` -------------------------------- ### Install @discordx/internal Source: https://discordx.js.org/api/internal/index.html Install the @discordx/internal package using npm or yarn. Requires Node.js version 16.6.0 or newer. ```bash npm install @discordx/internal yarn add @discordx/internal ``` -------------------------------- ### Run Bot with npm Source: https://discordx.js.org/docs/discordx/getting-started Start your Discordx bot using npm. Ensure the BOT_TOKEN environment variable is set. ```bash npm run start ``` -------------------------------- ### Dynamic Guild Resolver Example Source: https://discordx.js.org/docs/discordx/decorators/general/guild This example illustrates how to use a dynamic guild resolver to provide a list of guild IDs for command creation. ```APIDOC ## Example - Dynamic Guild Resolver ### Description To provide dynamic guild lists, use a guild resolver function. This allows for more flexible configuration of where commands are registered. ### Example ```typescript this._client = new Client({ botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)], }); ``` ``` -------------------------------- ### Install Lava Player Plugin Source: https://discordx.js.org/docs/plugin-lava-player Install the core Lava Player plugin using npm. This is the first step to integrating music playback capabilities into your discordx bot. ```bash npm install @discordx/plugin-lava-player ``` -------------------------------- ### Install tsx with pnpm Source: https://discordx.js.org/docs/discordx/basics/debugging Install tsx as a dev dependency using pnpm. This is required for debugging. ```bash pnpm add --save-dev tsx ``` -------------------------------- ### Run Bot with Bun Source: https://discordx.js.org/docs/discordx/getting-started Start your Discordx bot using Bun. Ensure the BOT_TOKEN environment variable is set. ```bash bun run start ``` -------------------------------- ### Run Bot with pnpm Source: https://discordx.js.org/docs/discordx/getting-started Start your Discordx bot using pnpm. Ensure the BOT_TOKEN environment variable is set. ```bash pnpm run start ``` -------------------------------- ### Install TypeScript Dev Dependency with Bun Source: https://discordx.js.org/docs/discordx/getting-started Install TypeScript as a development dependency using Bun. This is required for compiling your TypeScript code. ```bash bun add --dev typescript ``` -------------------------------- ### Install @discordx/internal with npm or yarn Source: https://discordx.js.org/api/internal Install the @discordx/internal package using either npm or yarn. Node.js version 16.6.0 or newer is required. ```bash npm install @discordx/internal ``` ```bash yarn add @discordx/internal ``` -------------------------------- ### @Slash Command Example Source: https://discordx.js.org/api/discordx Demonstrates how to define a slash command with options using the @Slash and @SlashOption decorators. ```APIDOC ## @Slash ### Description Discord has it's own command system now, you can simply declare commands and use Slash commands this way ### Method N/A (Decorator) ### Endpoint N/A (Decorator) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript @Discord() class Example { @Slash({ description: "say hello", name: "hello" }) hello( @SlashOption({ description: "enter your greeting", name: "message", required: true, type: ApplicationCommandOptionType.String, }) message: string, interaction: CommandInteraction, ): void { interaction.reply(`:wave: from ${interaction.user}: ${message}`); } } ``` ### Response #### Success Response (200) N/A (Interaction Reply) #### Response Example N/A (Interaction Reply) ``` -------------------------------- ### Login to Discord Source: https://discordx.js.org/api/discordx/classes/Client.html Starts the bot and logs it into Discord using the provided token. ```typescript client.login(token: string): Promise ``` -------------------------------- ### Run Bot with Yarn Source: https://discordx.js.org/docs/discordx/getting-started Start your Discordx bot using Yarn. Ensure the BOT_TOKEN environment variable is set. ```bash yarn run start ``` -------------------------------- ### Initialize Client and Application Commands Source: https://discordx.js.org/docs/discordx/decorators/command/slash Configure your Discordx client to initialize application commands on startup and execute interactions. This setup is crucial for slash commands to function. ```typescript import { Client, Events } from "discordx"; import { IntentsBitField } from "discord.js"; async function start() { const client = new Client({ botId: "test", intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, ], }); client.once(Events.ClientReady, async () => { await client.initApplicationCommands(); }); client.on(Events.InteractionCreate, (interaction) => { client.executeInteraction(interaction); }); await client.login("YOUR_TOKEN"); } start(); ``` -------------------------------- ### @ButtonComponent Handler Example Source: https://discordx.js.org/api/discordx Shows how to create a button component handler using the @ButtonComponent decorator and how to attach it to a slash command. ```APIDOC ## @ButtonComponent ### Description Create discord button handler with ease! ### Method N/A (Decorator) ### Endpoint N/A (Decorator) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript @Discord() class Example { @ButtonComponent({ id: "hello" }) handler(interaction: ButtonInteraction): void { interaction.reply(":wave:"); } @ButtonComponent({ id: "hello" }) handler2(interaction: ButtonInteraction): void { console.log(`${interaction.user} says hello`); } @Slash({ description: "test" }) test(interaction: CommandInteraction): void { const btn = new ButtonBuilder() .setLabel("Hello") .setStyle(ButtonStyle.Primary) .setCustomId("hello"); const buttonRow = new ActionRowBuilder().addComponents( btn, ); interaction.reply({ components: [buttonRow], }); } } ``` ### Response #### Success Response (200) N/A (Interaction Reply) #### Response Example N/A (Interaction Reply) ``` -------------------------------- ### Basic Reaction Handler Source: https://discordx.js.org/docs/discordx/decorators/general/reaction This example demonstrates how to set up a basic reaction handler using the @Reaction decorator to pin messages when a specific emoji is added. ```APIDOC ## @Reaction Create a reaction handler for messages using `@Reaction`. ### Example ```typescript @Discord() class Example { @Reaction({ emoji: "📌" }) async pin(reaction: MessageReaction): Promise { await reaction.message.pin(); } } ``` ``` -------------------------------- ### Declaring a Simple Command Option Source: https://discordx.js.org/docs/discordx/decorators/command/simple-command-option This example shows how to declare a string option named 'name' for a simple command. ```APIDOC ## @SimpleCommandOption ### Description Allows you to define options (parameters) for your simple commands. ### Signature ```typescript SimpleCommandOption(options: SimpleCommandOptionOptions); ``` ### Example Usage ```typescript @SimpleCommand() hello( @SimpleCommandOption({ name: "name", type: SimpleCommandOptionType.String }) name: string | undefined, command: SimpleCommandMessage ) { if (!name) return command.reply("usage: ``!hello ``"); command.message.reply(`hello ${name}`); } ``` ``` -------------------------------- ### build Source: https://discordx.js.org/api/discordx/classes/Client.html Build the client and initialize all systems. ```APIDOC ## build ### Description Build the client and initialize all systems. ### Method `build(): Promise` ### Returns Promise ``` -------------------------------- ### ERR_MODULE_NOT_FOUND Example Source: https://discordx.js.org/docs/faq/Errors/Common This error indicates that a module could not be found during the import process. Ensure the module path is correct and the module is installed. ```text CustomError: Cannot find module '/project/secret' imported from '/project/index.ts' ``` -------------------------------- ### Basic Event Handling with @On Source: https://discordx.js.org/docs/discordx/decorators/general/on This example demonstrates how to use the @On decorator to listen for the `MessageCreate` event and execute a method when a new message is sent. ```APIDOC ## @On decorator You can use this decorator to declare methods that will be executed whenever a Discord event is triggered. ### Example: ```typescript @Discord() class Example { @On({ event: Events.MessageCreate }) onMessage() { // ... } @Once({ event: Events.MessageDelete }) onMessageDelete() { // ... } } ``` ``` -------------------------------- ### initApplicationCommands Source: https://discordx.js.org/api/discordx/classes/ApplicationCommandManager.html Initializes application commands, optionally retaining deleted ones. ```APIDOC ## initApplicationCommands(retainDeleted?: boolean): Promise ### Description Initializes application commands. This method registers commands with Discord, and can optionally retain commands that were previously deleted. ### Parameters * **retainDeleted** (boolean) - Optional. If true, commands that were previously deleted will be retained. Defaults to false. ### Returns * Promise - A promise that resolves when the application commands have been initialized. ``` -------------------------------- ### Install tsx with Yarn Source: https://discordx.js.org/docs/discordx/basics/debugging Install tsx as a dev dependency using Yarn. This is required for debugging. ```bash yarn add --dev tsx ``` -------------------------------- ### Install tsx with npm Source: https://discordx.js.org/docs/discordx/basics/debugging Install tsx as a dev dependency using npm. This is required for debugging. ```bash npm install --save-dev tsx ``` -------------------------------- ### Client Initialization and Application Commands Source: https://discordx.js.org/docs/discordx/decorators/command/slash This section details the necessary steps to initialize your Discord client and manage application commands, including `initApplicationCommands` and `executeInteraction`. ```APIDOC ## Initialize client and application commands It require a bit of configuration at you Client initialization. You have to manually execute and initialize your application commands by using: * `client.initApplicationCommands()` * `client.executeInteraction(interaction)` This provide flexibility in your code ```typescript import { Client, IntentsBitField } from "discordx"; import { Events } from "discord.js"; async function start() { const client = new Client({ botId: "test", intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, ], }); client.once(Events.ClientReady, async () => { await client.initApplicationCommands(); }); client.on(Events.InteractionCreate, (interaction) => { client.executeInteraction(interaction); }); await client.login("YOUR_TOKEN"); } start(); ``` ``` -------------------------------- ### Client Constructor Source: https://discordx.js.org/api/discordx/classes/Client.html Initializes a new instance of the Client class. It accepts an options object for configuration. ```APIDOC ## constructor * new Client(options: ClientOptions): Client ### Parameters * options: ClientOptions ### Returns Client ``` -------------------------------- ### connect Method Source: https://discordx.js.org/api/lava-player/classes/Connection.html Establishes the WebSocket connection to the server. ```APIDOC ## connect * connect(): void ### Description Connects to the WebSocket server. ### Returns void ``` -------------------------------- ### Install TypeScript Dev Dependency with pnpm Source: https://discordx.js.org/docs/discordx/getting-started Install TypeScript as a development dependency using pnpm. This is required for compiling your TypeScript code. ```bash pnpm add --save-dev typescript ``` -------------------------------- ### Install TypeScript Dev Dependency with Yarn Source: https://discordx.js.org/docs/discordx/getting-started Install TypeScript as a development dependency using Yarn. This is required for compiling your TypeScript code. ```bash yarn add --dev typescript ``` -------------------------------- ### Initialize and Start discordx Client Source: https://discordx.js.org/docs/discordx/basics/client Use the discordx Client to manage your application's operations with Discord's API. Ensure you initialize application commands and log in with your bot token. ```typescript const client = new Client({ intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.GuildMembers, ], silent: false, }); client.on(Events.ClientReady, async () => { console.log(">> Bot started"); // to create/update/delete discord application commands await client.initApplicationCommands(); }); client.login(BOT_TOKEN); ``` -------------------------------- ### Install TypeScript Dev Dependency with npm Source: https://discordx.js.org/docs/discordx/getting-started Install TypeScript as a development dependency using npm. This is required for compiling your TypeScript code. ```bash npm install --save-dev typescript ``` -------------------------------- ### Rest Constructor Source: https://discordx.js.org/api/lava-player/classes/Rest.html Initializes a new Rest instance. ```APIDOC ## constructor * new Rest(node: BaseNode, base: string): Rest #### Parameters * node: BaseNode * base: string #### Returns Rest ``` -------------------------------- ### Initialize Client with DI Engine Source: https://discordx.js.org/docs/discordx/basics/dependency-injection Initialize the discordx client and set the DI engine before logging in. This is typically done in your main application file. ```typescript import { Events, IntentsBitField } from "discord.js"; import { Client, DIService, tsyringeDependencyRegistryEngine } from "discordx"; async function start() { DIService.engine = tsyringeDependencyRegistryEngine; const client = new Client({ botId: "test", intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, ], silent: false, }); await client.login("YOUR_TOKEN"); } start(); ``` -------------------------------- ### Get All Discord Classes with TypeDI Tokens Source: https://discordx.js.org/docs/discordx/basics/dependency-injection Fetch all Discord classes using TypeDI tokens by getting multiple instances associated with the TypeDiDependencyRegistryEngine token. ```typescript import { DIService } from "discordx"; function getAllDiscordClasses(): Set { return Container.getMany(TypeDiDependencyRegistryEngine.token); } ``` -------------------------------- ### Button Component Handler Example Source: https://discordx.js.org/docs/discordx/decorators/gui/button-component This example demonstrates how to use the @ButtonComponent decorator to create a button and handle its interaction. It also shows how to create and send a message with the button using the @Slash decorator. ```typescript import { Discord, ButtonComponent, Slash } from "@discord-bot/discordx"; import { ButtonInteraction, CommandInteraction, ButtonBuilder, ButtonStyle, ActionRowBuilder, MessageActionRowComponentBuilder } from "discord.js"; @Discord() class Example { @ButtonComponent({ id: "hello" }) handler(interaction: ButtonInteraction): void { interaction.reply(":wave:"); } @Slash({ description: "test" }) test(interaction: CommandInteraction): void { const btn = new ButtonBuilder() .setLabel("Hello") .setStyle(ButtonStyle.Primary) .setCustomId("hello"); const buttonRow = new ActionRowBuilder().addComponents( btn, ); interaction.reply({ components: [buttonRow], }); } } ``` -------------------------------- ### Constructor Source: https://discordx.js.org/api/di/classes/DefaultDependencyRegistryEngine.html Initializes a new instance of the DefaultDependencyRegistryEngine. ```APIDOC ## Constructors ### constructor * new DefaultDependencyRegistryEngine(): DefaultDependencyRegistryEngine #### Returns DefaultDependencyRegistryEngine ``` -------------------------------- ### Initialize Discord Client Source: https://discordx.js.org/docs/discordx/getting-started Initialize the Discord client with necessary intents and event handlers. This code snippet shows how to set up the client and log in using your bot token. ```typescript const client = new Client({ intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.GuildMembers, ], silent: false, }); client.on(Events.ClientReady, async () => { console.log(">> Bot started"); // to create/update/delete discord application commands await client.initApplicationCommands(); }); client.login(BOT_TOKEN); ``` -------------------------------- ### Node Constructor Source: https://discordx.js.org/api/music/classes/Node.html Initializes a new Node instance. ```APIDOC ## constructor * new Node(client: Client): Node ### Parameters * client: Client ### Returns Node ``` -------------------------------- ### Discord.js Modal Interaction Example Source: https://discordx.js.org/docs/discordx/decorators/gui/modal-component This example demonstrates how to use the @ModalComponent decorator to create a modal form and handle its submission. It includes setting up the modal, defining text input fields, and processing the user's input. ```typescript import { ApplicationCommandOptionType, CommandInteraction, ModalBuilder, TextInputBuilder, TextInputStyle, ModalSubmitInteraction, } from "discord.js"; import { Discord, Slash, ModalComponent } from "discordx"; // Helper to create Label components with text inputs class LabelBuilder { private label: string; private textInput: TextInputBuilder; setLabel(label: string): this { this.label = label; return this; } setTextInputComponent(textInput: TextInputBuilder): this { this.textInput = textInput; return this; } build() { // In a real scenario, you'd likely integrate this with ActionRowBuilder // For simplicity, this example assumes direct integration or a helper that does. // This is a placeholder for demonstration. return { label: this.label, textInput: this.textInput }; } } @Discord() class Example { @Slash({ description: "modal", djsOptions: { offer: [{ type: ApplicationCommandOptionType.String, name: "modal" }] } }) modal(interaction: CommandInteraction): void { // Create the modal const modal = new ModalBuilder() .setTitle("My Awesome Form") .setCustomId("AwesomeForm"); // Create text input fields const tvShowInputComponent = new LabelBuilder() .setLabel("Favorite TV show") .setTextInputComponent( new TextInputBuilder() .setCustomId("tvField") .setStyle(TextInputStyle.Short) .setRequired(true), ) .build(); const haikuInputComponent = new LabelBuilder() .setLabel("Write down your favorite haiku") .setTextInputComponent( new TextInputBuilder() .setCustomId("haikuField") .setStyle(TextInputStyle.Paragraph) .setRequired(true), ) .build(); // Add action rows to form // Assuming LabelBuilder.build() returns components compatible with addComponents // In a real Discord.js setup, you'd use ActionRowBuilder modal.addComponents([ { type: 1, components: [tvShowInputComponent.textInput.toJSON()] }, { type: 1, components: [haikuInputComponent.textInput.toJSON()] }, ]); // Present the modal to the user interaction.showModal(modal); } @ModalComponent() async AwesomeForm(interaction: ModalSubmitInteraction): Promise { const [favTVShow, favHaiku] = ["tvField", "haikuField"].map((id) => interaction.fields.getTextInputValue(id), ); await interaction.reply( `Favorite TV Show: ${favTVShow}, Favorite haiku: ${favHaiku}`, ); return; } } ``` -------------------------------- ### getTimeRemaining Source: https://discordx.js.org/api/utilities/interfaces/ITimedSet.html Get the time left until this item is removed from the set. ```APIDOC ## getTimeRemaining ### Description Get the time left until this item is removed from the set. ### Method `getTimeRemaining(key: T): number` ### Parameters #### Path Parameters - **key** (T) - Required - The key of the item to check. ### Returns - number - The remaining time in milliseconds. ``` -------------------------------- ### Node Constructor Source: https://discordx.js.org/api/lava-player/classes/Node.html Initializes a new Node instance with the provided options. ```APIDOC ## constructor * new Node(options: NodeOptions): Node ### Parameters * options: NodeOptions ### Returns Node ``` -------------------------------- ### DOn Accessors: key Source: https://discordx.js.org/api/discordx/classes/DOn.html Gets the name of the property or method being decorated. ```typescript get key(): string ``` -------------------------------- ### DOn Accessors: event Source: https://discordx.js.org/api/discordx/classes/DOn.html Gets or sets the name of the Discord event this decorator is for. ```typescript get event(): string ``` ```typescript set event(value: string): void ``` -------------------------------- ### Static create Source: https://discordx.js.org/api/discordx/classes/DApplicationCommand.html Creates a new DApplicationCommand from the provided data. ```APIDOC ## Static create ### Description Creates a new DApplicationCommand from the provided data. ### Method `create(data: CreateStructure): DApplicationCommand` ### Parameters #### Path Parameters - **data** (CreateStructure) - Required - The data to create the command with. ### Returns - DApplicationCommand - The newly created DApplicationCommand instance. ``` -------------------------------- ### DOn Accessors: discord Source: https://discordx.js.org/api/discordx/classes/DOn.html Gets or sets the DDiscord instance associated with the decorator. ```typescript get discord(): DDiscord ``` ```typescript set discord(value: DDiscord): void ``` -------------------------------- ### Queue Constructor Source: https://discordx.js.org/api/lava-queue/classes/Queue.html Initializes a new Queue instance. ```APIDOC ## constructor Queue ### Description Initializes a new Queue instance. ### Parameters - **node** (Node) - The Node instance to use for playback. - **guildId** (string) - The ID of the guild this queue belongs to. ### Returns - Queue: The newly created Queue instance. ``` -------------------------------- ### Get Guild Player Source: https://discordx.js.org/api/lava-player/index.html Retrieve an existing player instance for a specific guild ID. ```typescript const player = node.players.get("guild id"); ``` -------------------------------- ### DIService Constructor Source: https://discordx.js.org/api/di/classes/DIService.html Initializes a new instance of the DIService. ```APIDOC ## constructor * new DIService(): DIService ### Returns DIService ``` -------------------------------- ### DOn Accessors: index Source: https://discordx.js.org/api/discordx/classes/DOn.html Gets the zero-based index of the parameter being decorated, applicable only to parameter decorators. ```typescript get index(): number | undefined ``` -------------------------------- ### Class Decorators - getLinkedObjects Example Source: https://discordx.js.org/api/internal/functions/getLinkedObjects.html Shows how getLinkedObjects links class decorators applied to the same class. ```typescript // Class decorators - linked to the class itself @Discord() @Injectable() class MyBot {} ``` -------------------------------- ### Method Decorators - getLinkedObjects Example Source: https://discordx.js.org/api/internal/functions/getLinkedObjects.html Demonstrates how getLinkedObjects links method decorators applied to the same method. ```typescript // Method decorators - all linked together @Slash() @Permission() method() {} ``` -------------------------------- ### create Source: https://discordx.js.org/api/discordx/classes/DComponent.html Creates a new DComponent instance. ```APIDOC ## create ### Description Creates a new DComponent instance. ### Method Signature create(data: CreateStructure): DComponent ### Parameters #### Path Parameters * **data** (CreateStructure) - Required - The data to create the DComponent with. ### Returns * **DComponent** - A new instance of DComponent. ``` -------------------------------- ### DApplicationCommand Constructor Source: https://discordx.js.org/api/discordx/classes/DApplicationCommand.html Initializes a new instance of the DApplicationCommand class. ```APIDOC ## constructor * new DApplicationCommand(data: CreateStructure): DApplicationCommand #### Parameters * data: CreateStructure #### Returns DApplicationCommand ``` -------------------------------- ### Connection Accessors Source: https://discordx.js.org/api/lava-player/classes/Connection.html Information about the backoff accessor, which allows getting and setting the backoff strategy for the connection. ```APIDOC ## Accessors ### backoff * get backoff(): Backoff Getter for the backoff property. * set backoff(b: Backoff): void Setter for the backoff property. ### Parameters * `b`: Backoff ``` -------------------------------- ### ShardBot Class Structure Source: https://discordx.js.org/docs/discordx/basics/sharding Defines the basic structure of the ShardBot class with a static start method. ```typescript export class ShardBot {} ``` ```typescript export class ShardBot { static start(): void {} } ShardBot.start(); ``` -------------------------------- ### isReady Source: https://discordx.js.org/api/discordx/classes/Client.html Checks if the client is ready. ```APIDOC ## isReady ### Description Checks if the client is ready. ### Method `isReady(): this is Client` ``` -------------------------------- ### DIService.engine Accessor Source: https://discordx.js.org/api/di/classes/DIService.html Manages the dependency registry engine for DIService. It allows getting and setting the engine instance. ```APIDOC ## `Static`engine * get engine(): IDependencyRegistryEngine ### Returns IDependencyRegistryEngine * set engine(engine: IDependencyRegistryEngine): void ### Parameters * engine: IDependencyRegistryEngine ### Returns void ``` -------------------------------- ### DSimpleCommand Constructor Source: https://discordx.js.org/api/discordx/classes/DSimpleCommand.html Initializes a new instance of the DSimpleCommand class. ```APIDOC ## constructor * new DSimpleCommand(data: CreateStructure): DSimpleCommand ### Parameters * data: CreateStructure ### Returns DSimpleCommand ``` -------------------------------- ### Get Listeners Source: https://discordx.js.org/api/discordx/classes/Client.html Returns a copy of the array of listeners for a given event name. Useful for inspecting event handlers. ```typescript server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` ```typescript client.listeners(eventName: string | symbol): ((...args: any[]) => void)[] ``` -------------------------------- ### Constructor Source: https://discordx.js.org/api/di/classes/TsyringeDependencyRegistryEngine.html Initializes a new instance of the TsyringeDependencyRegistryEngine class. ```APIDOC ## constructor * new TsyringeDependencyRegistryEngine(): TsyringeDependencyRegistryEngine ### Returns TsyringeDependencyRegistryEngine ``` -------------------------------- ### Handling User Instance in Different Contexts Source: https://discordx.js.org/docs/discordx/decorators/command/simple-command-option Explains how the user instance type can vary depending on whether the command is used in DMs or guilds. ```APIDOC ## User Instance Context ### Description Understand the type of user instance received based on the command context (DM vs. Guild). - **DM:** You will receive `ClientUser` if the user mentions the bot. If the user mentions themselves, you will receive a `User`. Otherwise, an error may occur. - **Guilds:** It will always be `GuildMember | User`. ``` -------------------------------- ### Queue Methods Source: https://discordx.js.org/api/music/classes/Queue.html Methods for managing tracks, playback, and player settings. ```APIDOC ## Methods ### addTrack * addTrack(...track: T[]): void Adds tracks to the end of the queue. #### Parameters * ...track: T[] The tracks to be added. #### Returns void ### addTrackFirst * addTrackFirst(...track: T[]): void Adds tracks to the beginning of the queue. #### Parameters * ...track: T[] The tracks to be added. #### Returns void ### changeTrackPosition * changeTrackPosition(oldIndex: number, newIndex: number): void Changes the position of a track in the queue. #### Parameters * oldIndex: number The current index of the track. * newIndex: number The new index for the track. #### Returns void #### Throws Will throw an error if the indices are out of bounds. ### exit * exit(): void Exits the player, clearing the queue and destroying the LavaPlayer instance. #### Returns void ### join * join(data: Omit): void Joins a voice channel. #### Parameters * data: Omit The data required to join the channel. #### Returns void ### leave * leave(): void Leaves the voice channel. #### Returns void ### pause * pause(): void Pauses the playback. #### Returns void ### playNext * playNext(): T | null Plays the next track in the queue. #### Returns T | null The next track that was played or null if the queue is empty. ### removeAllTracks * removeAllTracks(): void Removes all tracks from the queue. #### Returns void ### removeTracks * removeTracks(...indices: number[]): void Removes tracks from the queue by their indices. #### Parameters * ...indices: number[] The indices of the tracks to be removed. #### Returns void ### resume * resume(): void Resumes the playback. #### Returns void ### seek * seek(seconds: number): T | null Seek the playback to specific position #### Parameters * seconds: number in milliseconds #### Returns T | null ### setLeaveOnFinish * setLeaveOnFinish(value: boolean): void Set leave on finish state #### Parameters * value: boolean #### Returns void ### setPlaybackInfo * setPlaybackInfo(info: PlaybackInfoAudioNodePayload): void Set playback info #### Parameters * info: PlaybackInfoAudioNodePayload #### Returns void ### setPlayerState * setPlayerState(state: AudioPlayerStatus): void set player state #### Parameters * state: AudioPlayerStatus #### Returns void ### setRepeatMode * setRepeatMode(mode: RepeatMode): void Sets the repeat mode for the queue. #### Parameters * mode: RepeatMode The repeat mode to be set. #### Returns void ### setVolume * setVolume(volume: number): void Sets the volume for playback. #### Parameters * volume: number The volume level to be set. #### Returns void ### shuffleTracks * shuffleTracks(): void Shuffles the tracks in the queue. #### Returns void ### skip * skip(): void Skips the current track. #### Returns void ### startPing * startPing(): void Starts a ping to keep the playback information updated. #### Returns void ### stopPing * stopPing(): void Stops the ping for updating playback information. #### Returns void ``` -------------------------------- ### Constructor Source: https://discordx.js.org/api/discordx/classes/DApplicationCommandOptionChoice.html Initializes a new instance of DApplicationCommandOptionChoice with the provided choice data. ```APIDOC ## constructor * new DApplicationCommandOptionChoice( data: SlashChoiceType, ): DApplicationCommandOptionChoice #### Parameters * data: SlashChoiceType The data for the choice, including name and value. ``` -------------------------------- ### Parameter Decorators - getLinkedObjects Example Source: https://discordx.js.org/api/internal/functions/getLinkedObjects.html Illustrates how getLinkedObjects links parameter decorators, with each parameter position forming separate links. ```typescript // Parameter decorators - each parameter position creates separate links method( @Option() @Required() param: string ) {} ``` -------------------------------- ### Build Project with Bun Source: https://discordx.js.org/docs/discordx/getting-started Build your Discordx project using Bun. This command compiles your TypeScript code into JavaScript. ```bash bun run build ``` -------------------------------- ### ApplicationCommandMixin Constructor Source: https://discordx.js.org/api/discordx/classes/ApplicationCommandMixin.html Initializes a new instance of the ApplicationCommandMixin class. ```APIDOC ## constructor ApplicationCommandMixin ### Description Initializes a new instance of the ApplicationCommandMixin class. ### Parameters * **command** (ApplicationCommand) - The application command object. * **instance** (DApplicationCommand) - The DApplicationCommand instance. ### Returns ApplicationCommandMixin - A new instance of ApplicationCommandMixin. ```