Skip to main content

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.

ParameterTypeDescription
titlestringTitle of the modal
contentstring|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.

ParameterTypeDescription
idstringID uses for the style element

Returns: void


deleteData Deprecated

Deletes a piece of stored data. This is different than saving null or undefined.

ParameterTypeDescription
pluginNamestringName of the plugin deleting data
keystringWhich piece of data to delete

Returns: void


disableSetting Deprecated

Disables a BetterDiscord setting by IDs.

ParameterTypeOptionalDefaultDescription
collectionstring"settings"Collection ID
categorystringnoneCategory ID in the collection
idstringnoneSetting ID in the category

Returns: void


enableSetting Deprecated

Enables a BetterDiscord setting by IDs.

ParameterTypeOptionalDefaultDescription
collectionstring"settings"Collection ID
categorystringnoneCategory ID in the collection
idstringnoneSetting ID in the category

Returns: void


findAllModules Deprecated

Finds multiple webpack modules using a filter.

ParameterTypeDescription
filterfunctionA 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.

ParameterTypeDescription
filterfunctionA 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.

ParameterTypeDescription
namestringDesired displayName property

Returns: any - Either the matching module or undefined


findModuleByProps Deprecated

Finds a webpack module by own properties.

ParameterTypeDescription
props...stringAny desired properties

Returns: any - Either the matching module or undefined


findModuleByPrototypes Deprecated

Finds a webpack module by own prototypes.

ParameterTypeDescription
protos...stringAny desired prototype properties

Returns: any - Either the matching module or undefined


getBDData Deprecated

Gets some data in BetterDiscord's misc data.

ParameterTypeDescription
keystringKey of the data to load

Returns: any - The stored data


getInternalInstance Deprecated

Gets the internal React data of a specified node.

ParameterTypeDescription
nodeHTMLElementNode 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.

ParameterTypeDescription
idstringID to use for style element
cssstringCSS to apply to the document

Returns: void


isSettingEnabled Deprecated

Gets a specific setting's status from BD.

ParameterTypeOptionalDefaultDescription
collectionstring"settings"Collection ID
categorystringnoneCategory ID in the collection
idstringnoneSetting ID in the category

Returns: boolean - If the setting is enabled


linkJS Deprecated

Automatically creates and links a remote JS script.

ParameterTypeDescription
idstringID of the script element
urlstringURL of the remote script

Returns: Promise - Resolves upon onload event


loadData Deprecated

Loads previously stored data.

ParameterTypeDescription
pluginNamestringName of the plugin loading data
keystringWhich 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.

ParameterTypeOptionalDefaultDescription
whatobjectnoneObject to be patched. You can can also pass class prototypes to patch all class instances.
methodNamestringnoneName of the function to be patched
optionsobjectnoneOptions object to configure the patch
options.afterfunctionnoneCallback 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.beforefunctionnoneCallback 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.insteadfunctionnoneCallback 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.oncebooleanfalseSet to true if you want to automatically unpatch method after first call
options.silentbooleanfalseSet 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.

ParameterTypeDescription
nodeHTMLElementNode to be observed
callbackfunctionFunction 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.

ParameterTypeOptionalDefaultDescription
optionsobjectnoneOptions object to configure the dialog
options.mode"open"|"save""open"Determines whether the dialog should open or save files
options.defaultPathstring~Path the dialog should show on launch
options.filtersArray.<object.<string, Array.<string>>>[]An array of file filters
options.titlestringnoneTitle for the titlebar
options.messagestringnoneMessage for the dialog
options.showOverwriteConfirmationbooleanfalseWhether the user should be prompted when overwriting a file
options.showHiddenFilesbooleanfalseWhether hidden files should be shown in the dialog
options.promptToCreatebooleanfalseWhether the user should be prompted to create non-existant folders
options.openDirectorybooleanfalseWhether the user should be able to select a directory as a target
options.openFilebooleantrueWhether the user should be able to select a file as a target
options.multiSelectionsbooleanfalseWhether the user should be able to select multiple targets
options.modalbooleanfalseWhether the dialog should act as a modal to the main window

Returns: Promise.<object> - Result of the dialog


saveData Deprecated

Saves JSON-serializable data.

ParameterTypeDescription
pluginNamestringName of the plugin saving data
keystringWhich piece of data to store
dataanyThe data to be saved

Returns: void


setBDData Deprecated

Sets some data in BetterDiscord's misc data.

ParameterTypeDescription
keystringKey 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.

ParameterTypeOptionalDefaultDescription
titlestringnoneTitle of the modal
childrenstring|ReactElement|Array.<(string|ReactElement)>noneSingle or mixed array of React elements and strings. Everything is wrapped in Discord's TextElement component so strings will show and render properly.
optionsobjectnoneOptions to modify the modal
options.dangerbooleanfalseWhether the main button should be red or not
options.confirmTextstringOkayText for the confirmation/submit button
options.cancelTextstringCancelText for the cancel button
options.onConfirmcallableNOOPCallback to occur when clicking the submit button
options.onCancelcallableNOOPCallback 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.

ParameterTypeOptionalDefaultDescription
contentstring|NodenoneContent of the notice
optionsobjectnoneOptions for the notice
options.typestring"info""error"
options.buttonsArray.<{label: string, onClick: function()}>noneButtons that should be added next to the notice text
options.timeoutnumber10000Timeout 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.

ParameterTypeOptionalDefaultDescription
contentstringnoneThe string to show in the toast
optionsobjectnoneOptions object. Optional parameter
options.typestring""Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: "".
options.iconbooleantrueDetermines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: true.
options.timeoutnumber3000Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: 3000.
options.forceShowbooleanfalseWhether to force showing the toast and ignore the BD setting

Returns: void


suppressErrors Deprecated

Wraps a given function in a try..catch block.

ParameterTypeDescription
methodfunctionFunction to wrap
messagestringAdditional 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.

ParameterTypeDescription
dataobjectData to be tested

Returns: boolean - Result of the test


toggleSetting Deprecated

Toggles a BetterDiscord setting by IDs.

ParameterTypeOptionalDefaultDescription
collectionstring"settings"Collection ID
categorystringnoneCategory ID in the collection
idstringnoneSetting ID in the category

Returns: void


unlinkJS Deprecated

Removes a remotely linked JS script.

ParameterTypeDescription
idstringID of the script element

Returns: void