A few utils to add stuff in frequent modules.
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();
}
The id of the menu to add to
The function that creates the item to add
— The number of the section to add to. Defaults to Replugged's section
— The index in the section to add to. Defaults to the end position
A callback to de-register the function
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();
}
The function that creates the button to add
Uninject Function.
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();
}
The slash command to add to register
A callback to de-register the command
Run code before a native module
Module to inject to
Function name on that module to inject
Code to run
Uninject function
Inject code into Discord's webpack modules.
Example