BdApi
BdApi
is a globally (window.BdApi
) accessible object for use by plugins and developers to make their lives easier.
Properties
ContextMenu
An instance of ContextMenu for interacting with context menus.
Type: ContextMenu
DOM
An instance of DOM to interact with the DOM.
Type: DOM
Data
An instance of Data to manage data.
Type: Data
Net
An instance of Net for networking requests.
Type: Net
Patcher
An instance of Patcher to monkey patch functions.
Type: Patcher
Plugins
An instance of AddonAPI to access plugins.
Type: AddonAPI
React
The React module being used inside Discord.
Type: React
ReactDOM
The ReactDOM module being used inside Discord.
Type: ReactDOM
ReactUtils
An instance of ReactUtils to work with React.
Type: ReactUtils
Themes
An instance of AddonAPI to access themes.
Type: AddonAPI
UI
An instance of UI to create interfaces.
Type: UI
Utils
An instance of Utils for general utility functions.
Type: Utils
Webpack
An instance of Webpack to search for modules.
Type: Webpack
emotes Deprecated
A reference object for BD's emotes.
Type: object
settings Deprecated
A reference object to get BD's settings.
Type: object
version
A reference string for BD's version.
Type: string
Methods
alert Deprecated
Shows a generic but very customizable modal.
Parameter | Type | Description |
---|---|---|
title | string | Title of the modal |
content | string|ReactElement|Array.<(string|ReactElement)> | A string of text to display in the modal |
Returns: void
clearCSS Deprecated
Removes a <style>
from the document corresponding to the given ID.
Parameter | Type | Description |
---|---|---|
id | string | ID uses for the style element |
Returns: void
deleteData Deprecated
Deletes a piece of stored data. This is different than saving null
or undefined
.
Parameter | Type | Description |
---|---|---|
pluginName | string | Name of the plugin deleting data |
key | string | Which piece of data to delete |
Returns: void
disableSetting Deprecated
Disables a BetterDiscord setting by IDs.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
collection | string | ✅ | "settings" | Collection ID |
category | string | ❌ | none | Category ID in the collection |
id | string | ❌ | none | Setting ID in the category |
Returns: void
enableSetting Deprecated
Enables a BetterDiscord setting by IDs.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
collection | string | ✅ | "settings" | Collection ID |
category | string | ❌ | none | Category ID in the collection |
id | string | ❌ | none | Setting ID in the category |
Returns: void
findAllModules Deprecated
Finds multiple webpack modules using a filter.
Parameter | Type | Description |
---|---|---|
filter | function | A filter given the exports, module, and moduleId. Returns true if the module matches. |
Returns: Array
- Either an array of matching modules or an empty array
findModule Deprecated
Finds a webpack module using a filter.
Parameter | Type | Description |
---|---|---|
filter | function | A filter given the exports, module, and moduleId. Returns true if the module matches. |
Returns: any
- Either the matching module or undefined
findModuleByDisplayName Deprecated
Finds a webpack module by displayName
property.
Parameter | Type | Description |
---|---|---|
name | string | Desired displayName property |
Returns: any
- Either the matching module or undefined
findModuleByProps Deprecated
Finds a webpack module by own properties.
Parameter | Type | Description |
---|---|---|
props | ...string | Any desired properties |
Returns: any
- Either the matching module or undefined
findModuleByPrototypes Deprecated
Finds a webpack module by own prototypes.
Parameter | Type | Description |
---|---|---|
protos | ...string | Any desired prototype properties |
Returns: any
- Either the matching module or undefined
getBDData Deprecated
Gets some data in BetterDiscord's misc data.
Parameter | Type | Description |
---|---|---|
key | string | Key of the data to load |
Returns: any
- The stored data
getInternalInstance Deprecated
Gets the internal React data of a specified node.
Parameter | Type | Description |
---|---|---|
node | HTMLElement | Node to get the internal React data from. |
Returns: object
- Either the found data or undefined
injectCSS Deprecated
Adds a <style>
to the document with the given ID.
Parameter | Type | Description |
---|---|---|
id | string | ID to use for style element |
css | string | CSS to apply to the document |
Returns: void
isSettingEnabled Deprecated
Gets a specific setting's status from BD.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
collection | string | ✅ | "settings" | Collection ID |
category | string | ❌ | none | Category ID in the collection |
id | string | ❌ | none | Setting ID in the category |
Returns: boolean
- If the setting is enabled
linkJS Deprecated
Automatically creates and links a remote JS script.
Parameter | Type | Description |
---|---|---|
id | string | ID of the script element |
url | string | URL of the remote script |
Returns: Promise
- Resolves upon onload event
loadData Deprecated
Loads previously stored data.
Parameter | Type | Description |
---|---|---|
pluginName | string | Name of the plugin loading data |
key | string | Which piece of data to load |
Returns: any
- The stored data
monkeyPatch Deprecated
Monkey-patches a method on an object. The patching callback may be run before, after or instead of target method. - Be careful when monkey-patching. Think not only about original functionality of target method and your changes, but also about developers of other plugins, who may also patch this method before or after you. Try to change target method behaviour as little as possible, and avoid changing method signatures. - Display name of patched method is changed, so you can see if a function has been patched (and how many times) while debugging or in the stack trace. Also, patched methods have property __monkeyPatched
set to true
, in case you want to check something programmatically.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
what | object | ❌ | none | Object to be patched. You can can also pass class prototypes to patch all class instances. |
methodName | string | ❌ | none | Name of the function to be patched |
options | object | ❌ | none | Options object to configure the patch |
options.after | function | ✅ | none | Callback that will be called after original target method call. You can modify return value here, so it will be passed to external code which calls target method. Can be combined with before . |
options.before | function | ✅ | none | Callback that will be called before original target method call. You can modify arguments here, so it will be passed to original method. Can be combined with after . |
options.instead | function | ✅ | none | Callback that will be called instead of original target method call. You can get access to original method using originalMethod parameter if you want to call it, but you do not have to. Can't be combined with before or after . |
options.once | boolean | ✅ | false | Set to true if you want to automatically unpatch method after first call |
options.silent | boolean | ✅ | false | Set to true if you want to suppress log messages about patching and unpatching |
Returns: function
- A function that cancels the monkey patch
onRemoved Deprecated
Adds a listener for when the node is removed from the document body.
Parameter | Type | Description |
---|---|---|
node | HTMLElement | Node to be observed |
callback | function | Function to run when removed |
Returns: void
openDialog Deprecated
Gives access to the Electron Dialog api. Returns a Promise
that resolves to an object
that has a boolean
cancelled and a filePath
string for saving and a filePaths
string array for opening.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
options | object | ❌ | none | Options object to configure the dialog |
options.mode | "open"|"save" | ✅ | "open" | Determines whether the dialog should open or save files |
options.defaultPath | string | ✅ | ~ | Path the dialog should show on launch |
options.filters | Array.<object.<string, Array.<string>>> | ✅ | [] | An array of file filters |
options.title | string | ✅ | none | Title for the titlebar |
options.message | string | ✅ | none | Message for the dialog |
options.showOverwriteConfirmation | boolean | ✅ | false | Whether the user should be prompted when overwriting a file |
options.showHiddenFiles | boolean | ✅ | false | Whether hidden files should be shown in the dialog |
options.promptToCreate | boolean | ✅ | false | Whether the user should be prompted to create non-existant folders |
options.openDirectory | boolean | ✅ | false | Whether the user should be able to select a directory as a target |
options.openFile | boolean | ✅ | true | Whether the user should be able to select a file as a target |
options.multiSelections | boolean | ✅ | false | Whether the user should be able to select multiple targets |
options.modal | boolean | ✅ | false | Whether the dialog should act as a modal to the main window |
Returns: Promise.<object>
- Result of the dialog
saveData Deprecated
Saves JSON-serializable data.
Parameter | Type | Description |
---|---|---|
pluginName | string | Name of the plugin saving data |
key | string | Which piece of data to store |
data | any | The data to be saved |
Returns: void
setBDData Deprecated
Sets some data in BetterDiscord's misc data.
Parameter | Type | Description |
---|---|---|
key | string | Key of the data to store |
Returns: any
- The stored data
showConfirmationModal Deprecated
Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
title | string | ❌ | none | Title of the modal |
children | string|ReactElement|Array.<(string|ReactElement)> | ❌ | none | Single or mixed array of React elements and strings. Everything is wrapped in Discord's TextElement component so strings will show and render properly. |
options | object | ✅ | none | Options to modify the modal |
options.danger | boolean | ✅ | false | Whether the main button should be red or not |
options.confirmText | string | ✅ | Okay | Text for the confirmation/submit button |
options.cancelText | string | ✅ | Cancel | Text for the cancel button |
options.onConfirm | callable | ✅ | NOOP | Callback to occur when clicking the submit button |
options.onCancel | callable | ✅ | NOOP | Callback to occur when clicking the cancel button |
Returns: string
- The key used for this modal
showNotice Deprecated
Shows a notice above Discord's chat layer.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
content | string|Node | ❌ | none | Content of the notice |
options | object | ❌ | none | Options for the notice |
options.type | string | ✅ | "info" | "error" |
options.buttons | Array.<{label: string, onClick: function()}> | ✅ | none | Buttons that should be added next to the notice text |
options.timeout | number | ✅ | 10000 | Timeout until the notice is closed. Will not fire when set to 0 . |
Returns: function
- A callback for closing the notice. Passing true
as first parameter closes immediately without transitioning out.
showToast Deprecated
Shows a toast similar to android towards the bottom of the screen.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
content | string | ❌ | none | The string to show in the toast |
options | object | ❌ | none | Options object. Optional parameter |
options.type | string | ✅ | "" | Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: "". |
options.icon | boolean | ✅ | true | Determines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: true . |
options.timeout | number | ✅ | 3000 | Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: 3000 . |
options.forceShow | boolean | ✅ | false | Whether to force showing the toast and ignore the BD setting |
Returns: void
suppressErrors Deprecated
Wraps a given function in a try..catch
block.
Parameter | Type | Description |
---|---|---|
method | function | Function to wrap |
message | string | Additional message to print when an error occurs |
Returns: function
- The new wrapped function
testJSON Deprecated
Tests a given object to determine if it is valid JSON.
Parameter | Type | Description |
---|---|---|
data | object | Data to be tested |
Returns: boolean
- Result of the test
toggleSetting Deprecated
Toggles a BetterDiscord setting by IDs.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
collection | string | ✅ | "settings" | Collection ID |
category | string | ❌ | none | Category ID in the collection |
id | string | ❌ | none | Setting ID in the category |
Returns: void
unlinkJS Deprecated
Removes a remotely linked JS script.
Parameter | Type | Description |
---|---|---|
id | string | ID of the script element |
Returns: void