Methods
-
<static> buildMenuItem( props ) → {object}
-
Description
Builds a single menu item. The only prop shown here is the type, the rest should match the actual component being built. View those to see what options exist for each, they often have less in common than you might think. See module:DiscordContextMenu.MenuItem for the majority of props commonly available. Check the documentation for the rest of the components.
Parameters
Name Type Description propsobject props used to build the item
Name Type Attributes Default Description typestring <optional> "text" type of the item, options: text, submenu, toggle, radio, custom, separator
Returns
Examples
// Creates a single menu item that prints "MENU ITEM" on click DiscordContextMenu.buildMenuItem({ label: "Menu Item", action: () => {console.log("MENU ITEM");} });// Creates a single toggle item that starts unchecked // and print the new value on every toggle DiscordContextMenu.buildMenuItem({ type: "toggle", label: "Item Toggle", checked: false, action: (newValue) => {console.log(newValue);} });Details
-
<static> buildMenuChildren( setup ) → {Array.<object>}
-
Description
Creates the all the items and groups of a context menu recursively. There is no hard limit to the number of groups within groups or number of items in a menu.
Parameters
Name Type Description setupArray.<object> array of item props used to build items. See module:DiscordContextMenu.buildMenuItem
Returns
Examples
// Creates a single item group item with a toggle item DiscordContextMenu.buildMenuChildren([{ type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => {console.log(newValue);} }] }]);// Creates two item groups with a single toggle item each DiscordContextMenu.buildMenuChildren([{ type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => { console.log(newValue); } }] }, { type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => { console.log(newValue); } }] }]);Details
-
<static> buildMenu( setup ) → {function}
-
Description
Creates the menu component including the wrapping
ContextMenu. Calls module:DiscordContextMenu.buildMenuChildren under the covers. Used to call in combination with module:DiscordContextMenu.openContextMenu.Parameters
Name Type Description setupArray.<object> array of item props used to build items. See module:DiscordContextMenu.buildMenuChildren
Returns
Details
-
<static> openContextMenu( event, menuComponent, config )
-
Parameters
Name Type Description eventMouseEvent The context menu event. This can be emulated, requires target, and all X, Y locations.
menuComponentfunction Component to render. This can be any react component or output of module:DiscordContextMenu.buildMenu
configobject configuration/props for the context menu
Name Type Attributes Default Description positionstring <optional> "right" default position for the menu, options: "left", "right"
alignstring <optional> "top" default alignment for the menu, options: "bottom", "top"
onClosefunction <optional> function to run when the menu is closed
noBlurEventboolean <optional> false No clue
Details
-
<static> getDiscordMenu( nameOrFilter ) → {Promise.<object>}
-
Description
Attempts to find and return a specific context menu type's module. Useful when patching the render of these menus.
Parameters
Name Type Description nameOrFilterstring | function name of the context menu type
Returns
Details
-
<static> forceUpdateMenus()
-
Description
Calls
forceUpdate()on all context menus it can find. Useful for after patching a menu.Details
Type Definitions
-
MenuItemOnClick( event )
-
Description
Fires when the item is clicked.
Parameters
Name Type Description eventMouseEvent The event generated on click
Details