replugged

    Class Injector

    Inject code into Discord's webpack modules.

    import { Injector, webpack } from "replugged";

    const injector = new Injector();

    export async function start() {
    const typingMod = (await webpack.waitForModule<{
    startTyping: (channelId: string) => void;
    }>(
    webpack.filters.byProps("startTyping")
    ));

    injector.after(typingMod, "startTyping", ([channel]) => {
    console.log(`Typing in channel ID ${channel}`);
    });
    }

    export function stop() {
    injector.uninjectAll();
    }
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    utils: {
        addMenuItem: <
            T extends Record<string, unknown> = Record<string, unknown>,
        >(
            navId: ContextMenuTypes,
            item: GetContextItem<T>,
            sectionId?: undefined | number | ((props: ContextMenuProps) => number),
            indexInSection?: number | ((props: ContextMenuProps) => number),
        ) => () => void;
        addPopoverButton: (item: GetButtonItem) => () => void;
        registerSlashCommand: <const T extends CommandOptions>(
            cmd: RepluggedCommand<T>,
        ) => () => void;
    } = ...

    A few utils to add stuff in frequent modules.

    Type declaration

    • addMenuItem: <T extends Record<string, unknown> = Record<string, unknown>>(
          navId: ContextMenuTypes,
          item: GetContextItem<T>,
          sectionId?: undefined | number | ((props: ContextMenuProps) => number),
          indexInSection?: number | ((props: ContextMenuProps) => number),
      ) => () => void

      A utility function to add an item to any context menu. By default, items are placed in a group for custom items, though that can be customized with sectionId and indexInSection

      import { Injector, components, types } from "replugged";
      const { ContextMenu: { MenuItem } } = components;
      const { ContextMenuTypes } = types;

      const injector = new Injector();

      export function start() {
      injector.utils.addMenuItem(ContextMenuTypes.UserContext, // Right-clicking a user
      (data, menu) => {
      return <MenuItem
      id="my-item"
      label="An Item!"
      action={() => console.log(data)}
      />
      }
      )
      }

      export function stop() {
      injector.uninjectAll();
      }
    • addPopoverButton: (item: GetButtonItem) => () => void

      A utility function to add a button to any message popover.

      import { Injector, webpack } from "replugged";

      const injector = new Injector();

      export function start() {
      injector.utils.addPopoverButton((msg: Message, channel: Channel) => {
      return {
      label: "Click the button!",
      icon: myVeryCoolIcon(), // Cool icon
      onClick: () => {
      // do stuff here when someone left clicks the button
      },
      onContextMenu: () => {
      // do other stuff here when someone right clicks the button
      },
      };
      });
      }

      export function stop() {
      injector.uninjectAll();
      }
    • registerSlashCommand: <const T extends CommandOptions>(cmd: RepluggedCommand<T>) => () => void

      A utility function to add a custom slash command.

      import { Injector, types } from "replugged";

      const injector = new Injector();

      export function start() {
      injector.utils.registerSlashCommand({
      name: "use",
      description: "a command meant to be used",
      usage: "/use",
      executor: (interaction) => {},
      })
      }

      export function stop() {
      injector.uninjectAll();
      }

    Methods

    • Run code after a native module

      Type Parameters

      • T extends Record<U, AnyFunction>
      • U extends string
      • A extends unknown[] = Parameters<T[U]>
      • R = ReturnType<T[U]>

      Parameters

      • obj: T

        Module to inject to

      • funcName: U

        Function name on that module to inject

      • cb: AfterCallback<A, R>

        Code to run

      Returns () => void

      Uninject function

    • Run code before a native module

      Type Parameters

      • T extends Record<U, AnyFunction>
      • U extends string
      • A extends unknown[] = Parameters<T[U]>

      Parameters

      • obj: T

        Module to inject to

      • funcName: U

        Function name on that module to inject

      • cb: BeforeCallback<A>

        Code to run

      Returns () => void

      Uninject function

    • Run code instead of a native module

      Type Parameters

      • T extends Record<U, AnyFunction>
      • U extends string
      • A extends unknown[] = Parameters<T[U]>
      • R = ReturnType<T[U]>

      Parameters

      • obj: T

        Module to inject to

      • funcName: U

        Function name on that module to inject

      • cb: InsteadCallback<A, R>

        Code to run

      Returns () => void

      Uninject function

    MMNEPVFCICPMFPCPTTAAATR