UNPKG

discord-components-v2-masteruse

Version:

A TypeScript/JavaScript package for simplified Discord.js component interactions.

85 lines (64 loc) 2.34 kB
# Discord Components V2 A TypeScript/JavaScript package for simplified Discord.js component interactions. This package abstracts away direct Discord API calls, making it easy for both beginners and advanced users to build interactive Discord bots. ## Features - Single unified import: access all components via one entry point - Supports Buttons, Select Menus, Modals, and Discord Client setup - Compatible with multiple versions of discord.js - Beginner-friendly, robust for advanced use ## Installation ```bash npm install discord-components-v2-masteuser discord.js ``` ## Usage Import the package entry point: ```typescript const { ComponentsV2 } = require('discord-components-v2-masteuser'); // or for ES Modules: import { ComponentsV2 } from 'discord-components-v2-masteuser'; ``` ### Example: Basic Bot Setup ```typescript const client = new ComponentsV2.DiscordClient('YOUR_BOT_TOKEN'); client.onInteraction((interaction) => { ComponentsV2.Button.handle(interaction, (i) => { // Handle button click }); ComponentsV2.SelectMenu.handle(interaction, (i) => { // Handle select menu selection }); ComponentsV2.Modal.handle(interaction, (i) => { // Handle modal submit }); }); ``` ### Creating a Button ```typescript const myButton = new ComponentsV2.Button('Click Me').setCustomId('my_button'); ``` ### Creating a Select Menu ```typescript const myMenu = new ComponentsV2.SelectMenu('Choose an option') .addOption('Option 1', '1') .addOption('Option 2', '2') .setCustomId('my_menu'); ``` ### Creating a Modal ```typescript const myModal = new ComponentsV2.Modal('My Modal').setCustomId('my_modal'); ``` ## Implementation Guide 1. Install dependencies as shown above. 2. Import `ComponentsV2` from the package entry point. 3. Initialize your Discord client and set up interaction handlers. 4. Create and use components as needed. ## Compatibility - Works with discord.js v14 and above - TypeScript and JavaScript supported ## Best Practices - Keep your interaction handlers simple and modular - Use the provided classes to avoid direct API calls - Refer to the examples for common patterns ## License MIT --- For more advanced usage and troubleshooting, see the documentation or open an issue on GitHub.