Skip to content

BdApi

BdApi is a globally (window.BdApi) accessible object for use by plugins and developers to make their lives easier.

Properties

Components

A set of react components plugins can make use of.

Type: Components


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


Logger

An instance of Logger for logging information.

Type: Logger


Net

An instance of Net for using network related tools.

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

DANGER

All methods directly on the BdApi object have been deprecated for a long time and are slated for removal. Do not use these in new projects!

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