Sheweny Framework

website·Indexed 29 days ago

https://sheweny.js.org/

A framework for creating Discord bots, providing a structured way to manage commands, events, buttons, select-menus, and modals. It includes a dedicated CLI for project setup and built-in managers for handling bot interactions and inhibitors.

Tokens
19.6K
Snippets
103
Records
190
Agent score
56%

What's inside Sheweny

  1. Overview of the Sheweny framework

    Sheweny is a progressive framework designed to simplify the creation of Discord bots. It features a CLI to make the framework accessible to beginners and provides streamlined methods for setting up interactions.
  2. Overview of the Sheweny framework

    Sheweny is a progressive framework designed to simplify the creation of Discord bots. It features a CLI to make the framework accessible to beginners and provides streamlined tools for setting up bot interactions.
  3. Use the sheweny CLI prefixes and help system

    The sheweny command line interface supports two prefixes: sheweny and shw. You can use either to execute CLI commands. To access the built-in help system, use the --help flag.
    sheweny --help
  4. Understand Sheweny's modular architecture

    Sheweny is designed with a modular architecture, allowing developers to selectively use only the specific components, structures, or managers required for their project rather than importing the entire library.
  5. Manage framework components using Managers

    The framework provides dedicated Manager classes to handle various components. These replace the previous 'Handler' system. Available managers include:

    • CommandsManager: Manages commands and handles ApplicationPermissions.
    • ButtonsManager: Manages buttons.
    • SelectMenusManager: Manages select-menus.
    • InhibitorsManager: Manages inhibitors.
  6. Configure Base Manager options

    BaseManagerOptions provides the fundamental configuration shared across different managers. It controls where files are located and how they are loaded.
    interface BaseManagerOptions {
      directory: string; // The main directory of the commands/files
      loadAll: boolean;   // Whether the framework should load all files in the directory
      default: number;    // The default cooldown period
    }
  7. Use ShewenyWarning to handle environment-specific warnings

    The ShewenyWarning class is used to trigger warnings. In development mode, it outputs a warning to the browser console. In production mode, it emits a warn event.
  8. Match select-menus using regular expressions

    Instead of providing a static list of IDs in the SelectMenu constructor, you can provide an array containing regular expressions. This allows a single listener to match multiple select-menu IDs based on a pattern.
    import { SelectMenu } from 'sheweny';
    import type { ShewenyClient } from 'sheweny';
    import type { SelectMenuInteraction } from 'discord.js';
    
    export class SelectRegex extends SelectMenu {
      constructor(client: ShewenyClient) {
        super(client, [/select-[0-9]+/]); // Matches IDs like select-1, select-2, etc.
      }
    
      execute(selectMenu: SelectMenuInteraction) {
        console.log(selectMenu);
      }
    }
  9. Create a basic button listener in sheweny

    To handle button interactions in sheweny, create a class that extends the Button class. The constructor must call super(client, ids), where ids is an array of button IDs that this listener should handle. The execute(button) method contains the logic to run when a matching button is clicked.
    import { Button } from 'sheweny';
    import type { ShewenyClient } from 'sheweny';
    import type { ButtonInteraction } from 'discord.js';
    
    export class Btns extends Button {
      constructor(client: ShewenyClient) {
        super(client, ['btnId1', 'btnId2']);
      }
    
      execute(button: ButtonInteraction) {
        console.log(button);
      }
    }
  10. Avoid synchronous functions in production

    Avoid using synchronous functions and methods in production as they block the executing process and reduce app performance. Always prefer asynchronous versions of functions. Synchronous calls are only justified during the initial startup phase. To identify synchronous API usage in Node.js 4.0+, use the --trace-sync-io command-line flag.
  11. Utilize Loader V2 features for project structures

    Loader V2 introduces several improvements to how structures are loaded:

    • Support for custom project structures.
    • Support for arrays of structures and multiple exportations per file.
    • Ability to mix different types of structures within a single file.
    • Note: The loadFiles and readDirAndPush functions have been removed.