Skip to content

UI

UI is a utility class for creating user interfaces. Instance is accessible through the BdApi.

Properties

Methods

alert

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


buildSettingItem

Creates a single setting wrapped in a setting item that has a name and note. The shape of the object should match the props of the component you want to render, check the BdApi.Components section for details. Shown below are ones common to all setting types.

ParameterTypeOptionalDefaultDescription
settingobjectnone
setting.typestringnoneOne of: dropdown, number, switch, text, slider, radio, keybind, color, custom
setting.idstringnoneIdentifier to used for callbacks
setting.namestringnoneVisual name to display
setting.notestringnoneVisual description to display
setting.valueanynoneCurrent value of the setting
setting.childrenReactElementnoneOnly used for "custom" type
setting.onChangeCallableFunctionnoneCallback when the value changes (only argument is new value)
setting.disabledbooleanfalseWhether this setting is disabled
setting.inlinebooleantrueWhether the input should render inline with the name (this is false by default for radio type)

Returns: void


buildSettingsPanel

Creates a settings panel (react element) based on json-like data.

The settings array here is an array of the same settings types described in buildSetting above. However, this API allows one additional setting "type" called category. This has the same properties as the Group React Component found under the Components API.

onChange will always be given 3 arguments: category id, setting id, and setting value. In the case that you have settings on the "root" of the panel, the category id is null. Any onChange listeners attached to individual settings will fire before the panel-level change listener.

onDrawerToggle is given 2 arguments: category id, and the current shown state. You can use this to save drawer states.

getDrawerState is given 2 arguments: category id, and the default shown state. You can use this to recall a saved drawer state.

ParameterTypeOptionalDefaultDescription
propsobjectnone
props.settingsArray.<object>noneArray of settings to show
props.onChangeCallableFunctionnoneFunction called on every change
props.onDrawerToggleCallableFunctionnoneOptionally used to save drawer states
props.getDrawerStateCallableFunctionnoneOptionially used to recall drawer states

Returns: void


createTooltip

Creates a tooltip to automatically show on hover.

ParameterTypeOptionalDefaultDescription
nodeHTMLElementnoneDOM node to monitor and show the tooltip on
contentstring|HTMLElementnoneString to show in the tooltip
optionsobjectnoneAdditional options for the tooltip
options.style"primary"|"info"|"success"|"warn"|"danger""primary"Correlates to the Discord styling/colors
options.side"top"|"right"|"bottom"|"left""top"Can be any of top, right, bottom, left
options.preventFlipbooleanfalsePrevents moving the tooltip to the opposite side if it is too big or goes offscreen
options.disabledbooleanfalseWhether the tooltip should be disabled from showing on hover

Returns: Tooltip - The tooltip that was generated.


openDialog

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-existent 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


showChangelogModal

Shows a changelog modal in a similar style to Discord's. Customizable with images, videos, colored sections and supports markdown.

The changes option is a array of objects that have this typing:

ts
interface Changes {
    title: string;
    type: "fixed" | "added" | "progress" | "changed";
    items: Array<string>;
    blurb?: string;
}
ParameterTypeOptionalDefaultDescription
optionsobjectnoneInformation to display in the modal
options.titlestringnoneTitle to show in the modal header
options.subtitlestringnoneTitle to show below the main header
options.blurbstringnoneText to show in the body of the modal before the list of changes
options.bannerstringnoneURL to an image to display as the banner of the modal
options.videostringnoneYoutube link or url of a video file to use as the banner
options.posterstringnoneURL to use for the video freeze-frame poster
options.footerstring|ReactElement|Array.<(string|ReactElement)>noneWhat to show in the modal footer
options.changesArray.<Changes>noneList of changes to show (see description for details)

Returns: string - The key used for this modal.


showConfirmationModal

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
options.onClosecallableNOOPCallback to occur when exiting the modal

Returns: string - The key used for this modal.


showNotice

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

This shows a toast similar to android towards the bottom of the screen.

ParameterTypeOptionalDefaultDescription
contentstringnoneThe string to show in the toast
optionsobjectnoneOptions for the toast
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