Replugged Developer Guide

website·Indexed 33 days ago

https://guide.replugged.dev

Documentation for developing addons, plugins, and themes for Replugged. Includes guides on using Webpack modules, common components like TextArea and Tooltip, plugin settings, manifest configuration, and the Replugged Addon Store released in v4.3.0.

Tokens
29.3K
Snippets
198
Records
252
Agent score
51%

What's inside Replugged

  1. Define InviteSuggestion structure

    The InviteSuggestion type provides metadata about an invite suggestion, including whether it is filtered and the total number of available suggestions.
    interface InviteSuggestion {
      isAffinitySuggestion: boolean;
      isFiltered: boolean;
      numAffinityConnections: number;
      numTotal: number;
      rowNum: number;
    }
  2. Understand ContextMenuProps for render functions

    When providing a render function to open or openLazy, the function receives ContextMenuProps. These props provide metadata about the menu's environment, including the target HTMLElement, the current theme, and the context (defaults to 'APP').
    interface ContextMenuProps {
      className: string;
      config: ContextMenusOptions;
      context: string; // default: 'APP'
      onHeightUpdate: () => void;
      position: Tooltip.Positions;
      target: HTMLElement;
      theme: string;
    }
  3. Get guild selection state and timestamps

    Use getState() to retrieve a State object containing information about guild selections, including the current and last selected guild IDs and a record of selection timestamps.
    const state = guildsStore.getState();
    console.log(state.selectedGuildId); // Current selected guild id
    console.log(state.lastSelectedGuildId); // Last selected guild id
    console.log(state.selectedGuildTimestampMillis); // Record<string, number> of timestamps
  4. Extract functions and keys from modules

    Replugged provides utilities to find specific functions within a module based on their source code. getFunctionBySource returns the function itself, while getFunctionKeyBySource returns the property name (key), which is required for using the Injector.
    import { Injector, webpack } from "replugged";
    const { getBySource, getFunctionBySource, getFunctionKeyBySource } = webpack;
    const injector = new Injector();
    
    export function start() {
      const module = getBySource("YOUR QUERY HERE");
      
      // Get the function directly
      const functionInModule = getFunctionBySource(module, "YOUR QUERY HERE");
      
      // Get the key for injection
      const keyInModule = getFunctionKeyBySource(module, "YOUR QUERY HERE");
    
      injector.after(module, keyInModule, (args, res) => {
        console.log("Function was called!", { args, res });
      });
    }
  5. Create an installation link for a Replugged theme

    You can create a direct installation link that prompts users to install your theme in Replugged using the format: https://replugged.dev/install?identifier={identifier}&source={source}.

    Parameters:

    • identifier: Must match the updater.id in the manifest.
    • source: Must match updater.source in the manifest (currently supports github or store).
    • id: (Optional) Required only if the update source is GitHub and the release contains multiple themes. Matches the id in the manifest.
    [![Install in Replugged](https://img.shields.io/badge/-Install%20in%20Replugged-blue?style=for-the-badge&logo=none)](https://replugged.dev/install?identifier=YOUR_ADDON_INFO_HERE&source=github)
  6. Develop and test Replugged plugins

    Use the watch script to automatically rebuild the plugin when changes are detected. By default, this will also reload the plugin within Discord.

    • Automatic Reloading: Run pnpm run watch.
    • Disable Reloading: Use the --no-reload flag if you want to rebuild without automatically reloading in Discord.
    • Full Reload: Some changes (like plaintext patches) require a full Discord reload (Ctrl + R).
    pnpm run watch
    # Or to disable auto-reload
    pnpm run watch --no-reload
  7. Set up the Replugged guide development environment

    The Replugged guide is built with Docusaurus. To set up the local development environment, clone the repository and install dependencies using pnpm. Start the development server to preview changes on localhost:3000 with automatic reloading.
    pnpm install
    pnpm start
  8. Import and access common modules in Replugged

    Replugged provides a set of commonly used modules accessible via the common object. When developing plugins, always import from the main replugged package and destructure the required module. Avoid importing directly from internal paths like replugged/dist/... as they will not function correctly. For debugging or testing in Discord DevTools, these modules are available via the global replugged.common object.
    import { common } from "replugged";
  9. Prerequisites for Replugged plugin development

    To develop plugins for Replugged, you need the following technical stack and tools:

    • Languages: TypeScript (recommended) or JavaScript. Basic knowledge of React is also required as Discord is built with it.
    • Environment: Node.js, pnpm, and git installed on your machine.
    • Editor: VSCode is recommended.
    • Testing Environment: Discord with the Replugged client installed.
  10. Manage plugin lifecycle with start and stop functions

    A Replugged plugin's index file (typically src/index.ts) must export two functions: start and stop. All injection logic should be initialized within start, and all injections must be cleaned up within stop to prevent memory leaks or unexpected behavior.
  11. Access common Replugged modules

    Replugged provides a set of commonly used modules accessible via the common export from the replugged package. When importing, you must destructure the desired module from the main replugged entry point. Do not import modules directly from internal paths like replugged/dist/... as they will not function correctly.
    import { common } from "replugged";