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();
}

Constructors

Properties

Methods

Constructors

Properties

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

A few utils to add stuff in frequent modules.

Type declaration

  • addMenuItem: (<T>(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();
    }
      • <T>(navId, item, sectionId?, indexInSection?): (() => void)
      • Type Parameters

        • T extends Record<string, unknown> = Record<string, unknown>

        Parameters

        • navId: ContextMenuTypes

          The id of the menu to add to

        • item: GetContextItem<T>

          The function that creates the item to add

        • sectionId: undefined | number | ((props: ContextMenuProps) => number) = undefined

          — The number of the section to add to. Defaults to Replugged's section

        • indexInSection: number | ((props: ContextMenuProps) => number) = Infinity

          — The index in the section to add to. Defaults to the end position

        Returns (() => void)

        A callback to de-register the function

          • (): void
          • Returns void

  • 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();
    }
      • (item): (() => void)
      • Parameters

        Returns (() => void)

        Uninject Function.

          • (): void
          • Returns void

  • registerSlashCommand: (<const T>(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();
    }
      • <const T>(cmd): (() => void)
      • Type Parameters

        Parameters

        Returns (() => void)

        A callback to de-register the command

          • (): void
          • Returns void

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

      • (): void
      • Returns void

  • 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

      • (): void
      • Returns void

  • 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

      • (): void
      • Returns void